Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements.

Slides:



Advertisements
Similar presentations
Pemrograman VisualMinggu …3… Page 1 MINGGU Ke Tiga Pemrograman Visual Pokok Bahasan: Class, Objects, Methods and Instance Variable Tujuan Instruksional.
Advertisements

Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Chapter 11: Implementing Inheritance and Association Visual Basic.NET Programming: From Problem Analysis to Program Design.
More about classes and objects Classes in Visual Basic.NET.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Chapter 12 Java Code Examples Showing Problem Domain Classes.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
1 Prototyping for HCI Spring 2004 (Week 8) Jorge A. Toro.
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 7: Working with Arrays
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
CS708 Fall 2004 Professor Douglas Moody –MW – 2:15-3:55 pm –Friday – 6:00-9:20 pm – – –Web Site: websupport1.citytech.cuny.edu.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Chapter 15 - Creating More Complex Database Applications 1 Chapter 15 Creating More Complex Database Applications.
Chapter 9 - Implementing Association Relationships1 Chapter 9 Implementing Association Relationships.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 12: Adding Functionality to Your Classes.
Chapter 8 More Object Concepts
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
JavaScript, Fourth Edition
What is inheritance? It is the ability to create a new class from an existing class.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.
Object-Oriented Application Development Using VB.NET 1 Chapter 6 Writing a Problem Domain Class Definition.
Object-Oriented Application Development Using VB.NET 1 Chapter 6 Writing a Problem Domain Class Definition.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Object Oriented Analysis and Design Class and Object Diagrams.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Introduction to Object-Oriented Programming Lesson 2.
Object-Oriented Application Development Using VB.NET 1 Chapter 5 Object-Oriented Analysis and Design.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Object-Oriented Programming: Inheritance and Polymorphism.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
ILM Proprietary and Confidential -
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Object-Oriented Programming: Classes and Objects.
These materials where developed by Martin Schray
Objects as a programming concept
Chapter 3: Using Methods, Classes, and Objects
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
MSIS 670 Object-Oriented Software Engineering
Inheritance, Polymorphism, and Interfaces. Oh My
Tonga Institute of Higher Education
Creating More Complex Database Applications
Object-Oriented Programming: Inheritance and Polymorphism
Chapter 8 Class Inheritance and Interfaces
Presentation transcript:

Object-Oriented Application Development Using VB.NET 1 Creating a String Array Code to create a String array: ' declare a String array with 4 elements Dim stringArray(3) As String Elements of stringArray are reference variables of data type String

Object-Oriented Application Development Using VB.NET 2 Creating a String Array Code to create four String instances and populate the array elements stringArray(0) = "Hello" stringArray(1) = "World" stringArray(2) = "Wide" stringArray(3) = "Web" A specific element can be accessed using the index of that element String methods can be invoked for String instances referenced by array elements

Object-Oriented Application Development Using VB.NET 3 Creating a String Array

Object-Oriented Application Development Using VB.NET 4 Using the ArrayList Class Major limitation of arrays: fixed size ArrayList class –Member of System.Collections namespace –Creates dynamically resizable array – the number of elements can change during runtime

Object-Oriented Application Development Using VB.NET 5 Using the ArrayList Class Code to create an instance of ArrayList class: ' create an ArrayList instance with 3 elements Dim anArrayList As ArrayList = New ArrayList(3)

Object-Oriented Application Development Using VB.NET 6 Using the ArrayList Class Code to create four instances of String class: ' create String instances Dim s1 As String = New String("Hello") Dim s2 As String = New String("World") Dim s3 As String = New String("Wide") Dim s4 As String = New String("Web")

Object-Oriented Application Development Using VB.NET 7 Using the ArrayList Class Add method is used to populate the elements When a fourth element is added, the number of elements increases automatically anArrayList.Add(s1) anArrayList.Add(s2) anArrayList.Add(s3) anArrayList.Add(s4)

Object-Oriented Application Development Using VB.NET 8 Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationships –Show how instances of classes are associated, or connected, to each other –Indicate that the system requires information about these associations –Can be used to navigate from instance to instance following the association

Object-Oriented Application Development Using VB.NET 9 Identifying Association Relationships on Bradshaw Marina’s Class Diagram In a class diagram –An association relationship Appears as a line connecting classes –Multiplicity of the association Indicated by numbers written at both ends of the line

Object-Oriented Application Development Using VB.NET 10 Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationships in the Bradshaw class diagram: –A customer owns a boat –A boat is owned by a customer –A boat is assigned to a slip –A slip contains a boat –A dock contains many slips –A slip is attached to a dock –A slip is leased to a customer (Lease is an association class) –A customer leases a slip (Lease is an association class)

Object-Oriented Application Development Using VB.NET 11 Identifying Association Relationships on Bradshaw Marina’s Class Diagram

Object-Oriented Application Development Using VB.NET 12 Identifying Association Relationships on Bradshaw Marina’s Class Diagram Lease class –An example of an association class Exists because of the relationship between a slip and a customer –In the class diagram Shown as a class connected by a dashed line to an association between Slip and Customer

Object-Oriented Application Development Using VB.NET 13 Associating VB.NET Classes in a One-to-One Relationship Association relationship between Customer and Boat –Has two “directions” A customer owns a boat A boat is owned by a customer –Each direction of the relationship Must be defined separately by the system developer Must be handled separately with VB.NET

Object-Oriented Application Development Using VB.NET 14 Associating VB.NET Classes in a One-to-One Relationship To implement an association relationship in VB.NET –Use a reference variable as an attribute of a class A reference variable points to an actual instance

Object-Oriented Application Development Using VB.NET 15 Associating VB.NET Classes in a One-to-One Relationship

Object-Oriented Application Development Using VB.NET 16 Associating VB.NET Classes in a One-to-One Relationship A Customer reference variable –Points to a Customer instance –If added as an attribute in the Boat class, each Boat instance can Point to a Customer instance Invoke the customer’s methods

Object-Oriented Application Development Using VB.NET 17 Associating VB.NET Classes in a One-to-One Relationship A Boat reference variable –Points to a Boat instance –If added as an attribute in the Customer class, each Customer instance can Point to a Boat instance Invoke the boat’s methods

Object-Oriented Application Development Using VB.NET 18 Modifying the Customer Class Modifying the Customer class implements one direction of the association relationship –From Customer to Boat theBoat attribute –A Boat reference variable –Added to the Customer class –Used to implement a one-to-one association relationship with the Boat class

Object-Oriented Application Development Using VB.NET 19 Modifying the Customer Class Accessor methods –SetBoat Accepts a Boat reference as a parameter Assigns the reference to the attribute –GetBoat Returns the Boat reference

Object-Oriented Application Development Using VB.NET 20 Modifying the Customer Class Constructor –Sets the Boat reference variable to Nothing using the SetBoat method –Once Customer instance is created Boat reference variable can be set to an actual Boat reference

Object-Oriented Application Development Using VB.NET 21 Modifying the Boat Class Modifying the Boat class implements the other direction of the association relationship –A boat is owned by a customer theCustomer attribute –A Customer reference variable –Added to the Boat class –Used to implement a one-to-one association relationship with the Customer class

Object-Oriented Application Development Using VB.NET 22 Modifying the Boat Class Accessor methods –GetCustomer Returns the Customer reference –SetCustomer Accepts a Customer reference as a parameter Assigns the reference to the attribute

Object-Oriented Application Development Using VB.NET 23 Adding Functionality to the Boat Class Functionality of classes that have association relationships can be increased AssignBoatToCustomer custom method –Added in Boat –Establishes the association between Boat and Customer in both directions in one step

Object-Oriented Application Development Using VB.NET 24 Adding Functionality to the Boat Class Mandatory association between Boat and Customer –Possible because Bradshaw Marina does not want to keep information about a boat if its owner is not a customer –Done by Adding a Customer reference parameter to the Boat constructor

Object-Oriented Application Development Using VB.NET 25 Adding Functionality to the Boat Class Modified Boat TellAboutSelf method –Returns information about Boat Customer –Possible because A boat must be associated with a customer

Object-Oriented Application Development Using VB.NET 26 Associating Docks and Slips: A One- to-Many Association Relationship Association relationship between Slip and Dock –Two directions of the relationship Association relationship between Slip and Dock –One-to-one »A slip is attached to a dock Association relationship between Dock and Slip –One-to-many »A dock contains many slips

Object-Oriented Application Development Using VB.NET 27 Associating Docks and Slips: A One- to-Many Association Relationship To implement –A one-to-one association relationship between Slip and Dock Use the technique used to implement the Customer and Boat associations –A one-to-many association relationship between Dock and Slip Requires that a dock instance have reference variables for more than one slip –Use an ArrayList in the Dock class to hold many Slip reference variables

Object-Oriented Application Development Using VB.NET 28 Associating Docks and Slips: A One- to-Many Association Relationship ArrayList class –Can be used to instantiate a container that can hold many reference variables –Has methods which can be used to Add Slip references Retrieve Slip references

Object-Oriented Application Development Using VB.NET 29 Introducing the Dock Class Dock class –Four previous attributes An ID number A location Two Boolean variables indicating –Whether the dock has electricity –Whether the dock has water –Fifth attribute slips –An ArrayList –Implements the one-to-many association relationship

Object-Oriented Application Development Using VB.NET 30 Introducing the Dock Class Dock class constructor –Sets values for the four attributes –Instantiates the new ArrayList –Assigns the new ArrayList to the slips attribute GetSlips –A getter method –Returns the slips reference variable

Object-Oriented Application Development Using VB.NET 31 Introducing the Dock Class AddSlip custom method –Used to add a slip to the dock –Invoked by the Slip AddSlipToDock method –Contains the slips.Add(aSlip) statement Used to add a Slip reference to the ArrayList referenced by the variable slips

Object-Oriented Application Development Using VB.NET 32 Associating the Slip Class with Dock Modifications to the Slip class to implement the mandatory one-to-one association relationship –theDock attribute A Dock reference variable –Accessor methods for the Dock reference attribute

Object-Oriented Application Development Using VB.NET 33 Associating the Slip Class with Dock Modifications to the Slip class (Continued) –Modified constructor Expects a Dock reference parameter –Result: When a slip is instantiated, it must be associated with a dock Invokes the slip’s AddSlipToDock method –AddSlipToDock method establishes the association in both directions by »Invoking the dock’s AddSlip method using the Me keyword

Object-Oriented Application Development Using VB.NET 34 Associating the Slip Class with Dock Modifications to the Slip class (Continued) –A TellAboutSelf method Returns information about –The slip –The slip’s dock

Object-Oriented Application Development Using VB.NET 35 Adding the Boat and Customer Classes to the Slip Example Association relationship between Slip and Boat –Modifications to the Slip class A Boat reference attribute Accessor methods –GetBoat –SetBoat –Modifications to the Boat class A Slip reference attribute Accessor methods AssignBoatToSlip method

Object-Oriented Application Development Using VB.NET 36 Adding the Boat and Customer Classes to the Slip Example To include the Customer class in this example –Boat class does not need to be modified It is already designed to associate with a customer Given a Customer reference –Can navigate to find The customer’s boat The boat’s slip The slip’s dock

Object-Oriented Application Development Using VB.NET 37 Adding the Boat and Customer Classes to the Slip Example Given a Dock reference –Can navigate to Each slip The slip’s boat The customer who owns the boat

Object-Oriented Application Development Using VB.NET 38 Creating and Using an Association Class – Lease Lease class –An association class A Lease is like an association between a customer and a slip, but with attributes for –Start date –End date –Amount of lease, and so on –Subclasses AnnualLease DailyLease

Object-Oriented Application Development Using VB.NET 39 Creating and Using an Association Class – Lease Modifications to the Lease superclass –A Slip reference attribute –A Customer reference attribute –Accessor methods AnnualLease class –A subclass of Lease –Inherits the association between Lease and Slip Lease and Customer

Object-Oriented Application Development Using VB.NET 40 Creating and Using an Association Class – Lease No modifications needed for the Boat class –Reason: Boat is not directly associated with Lease Modifications to the Customer class –A Lease reference attribute –Accessor methods

Object-Oriented Application Development Using VB.NET 41 Creating and Using an Association Class – Lease Modifications to the Slip class –A Lease reference attribute –Accessor methods –LeaseAnnualSlip method Creates an AnnualLease instance