Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.

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.
UML Class Diagram. UML Class Diagrams2 Agenda What is a Class Diagram? Essential Elements of a UML Class Diagram Tips.
More about classes and objects Classes in Visual Basic.NET.
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
UML Class Diagram and Packages Written by Zvika Gutterman Adam Carmi.
Chapter 12 Java Code Examples Showing Problem Domain Classes.
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-Oriented Application Development Using VB.NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes.
Modelling classes Drawing a Class Diagram. Class diagram First pick the classes –Choose relevant nouns, which have attributes and operations. Find the.
Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships.
2-1 © Prentice Hall, 2004 Chapter 2: Introduction to Object Orientation (Adapted) Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra,
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
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.
Databases Illuminated Chapter 7 The Object-Oriented Model.
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.
Object-Oriented Analysis and Design
Chapter 9 - Implementing Association Relationships1 Chapter 9 Implementing Association Relationships.
Chapter 8 More Object Concepts
Chapter 5 - Writing a Problem Domain Class Definition1 Chapter 5 Writing a Problem Domain Class Definition.
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.
What is inheritance? It is the ability to create a new class from an existing class.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Chapter 12 - Designing Multiwindow Applications1 Chapter 12 Designing Multiwindow Applications 12.
Unified Modeling Language © 2002 by Dietrich and Urban1 ADVANCED DATABASE CONCEPTS Unified Modeling Language Susan D. Urban and Suzanne W. Dietrich Department.
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.
Chapter 8 - Additional Inheritance Concepts and Techniques1 Chapter 8 Additional Inheritance Concepts and Techniques.
UML Class Diagram Trisha Cummings. What we will be covering What is a Class Diagram? Essential Elements of a UML Class Diagram UML Packages Logical Distribution.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Lecture 1: UML Class Diagram September 12, UML Class Diagrams2 What is a Class Diagram? A class diagram describes the types of objects in the system.
Object Oriented Software Development
Dr. Azeddine Chikh IS444: Modern tools for applications development.
Object Oriented Analysis and Design Class and Object Diagrams.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Chapter 8 Inheritance Part 1. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Inheritance Inheritance is a fundamental object-oriented design technique.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
© 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.
Class Diagram Chapter 21 Applying UML and Patterns Craig Larman.
CS212: Object Oriented Analysis and Design Lecture 33: Class and Sequence Diagram.
Creating Classes from Other Classes Appendix D © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
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.
Mapping Objects ↔Relational DB. The Problem with Databases Databases store data in rows in tables, which are not like objects. We can simulate object.
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
Java Programming, Second Edition Chapter Three Using Methods, Classes, and Objects.
Object-Oriented Application Development Using VB.NET 1 Chapter 11 Using Multiple Forms with Problem Domain Classes.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Chapter 11 An introduction to object-oriented design.
Object-Oriented Application Development Using VB.NET 1 Chapter 15 Assembling a Three-Tier Windows Application.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
 2007 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Intro To Classes Review
Chapter 3: Using Methods, Classes, and Objects
Chapter 4 (part 2).
UML Class Diagram.
Advanced Java Programming
Creating More Complex Database Applications
Object Oriented System Design Class Diagrams
Presentation transcript:

Object-Oriented Application Development Using VB.NET 1 Chapter 9 Implementing Association Relationships

Object-Oriented Application Development Using VB.NET 2 Objectives In this chapter, you will: Identify association relationships on Bradshaw Marina’s class diagram Associate VB.NET classes in a one-to-one relationship Add functionality to the Boat class Associate Dock and Slips in a one-to-many relationship Add the Boat and Customer classes to the Slip example Create and use an association class—Lease

Object-Oriented Application Development Using VB.NET 3 Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationships –Show how instances of classes are associated, or connected, to each other. –Can be used to navigate from instance to instance following the association 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 4 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 5 Identifying Association Relationships on Bradshaw Marina’s Class Diagram

Object-Oriented Application Development Using VB.NET 6 Identifying Association Relationships on Bradshaw Marina’s Class Diagram Association relationship can be shown also as: –Aggregation relationship: One Instance contains another instance. For example, A town contains Shopping centers –Composition relationship: One Instance is composed of, or part of another instance. For example, Walls is a part of building. Lease class ( association class) Exists because of the relationship between a slip and a customer Shown as a class connected by a dashed line to an association between Slip and Customer

Object-Oriented Application Development Using VB.NET 7 Associating VB.NET Classes in a One-to-One Relationship Association relationship between Customer and Boat has two “directions” A customer owns a boat (Optional relationship) A boat is owned by a customer (Mandatory relationship) Each direction of the relationship must be defined separately by the system developer.

Object-Oriented Application Development Using VB.NET 8 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. It is a reference variable points to an actual instance. –Though, you can invoke the methods of that instance using that attribute.

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

Object-Oriented Application Development Using VB.NET 10 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 11 Associating VB.NET Classes in a One-to-One Relationship In the same way, 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 12 Modifying the Customer Class Adding theBoat attribute –A Boat reference variable –Added to the Customer class –Used to implement a one-to-one association relationship with the Boat class –Adding an attribute:- Private theBoat As Boat

Object-Oriented Application Development Using VB.NET 13 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 Accessor methods –SetBoat Public sub setBoat( aBoat as Boat) theBoat = aBoat End Sub –GetBoat Public Function getBoat( ) as Boat Return theBoat End Sub

Object-Oriented Application Development Using VB.NET 14 Modifying the Boat Class Adding theCustomer attribute –A Customer reference variable –Added to the Boat class –Used to implement a one-to-one association relationship with the Customer class –Adding an attribute: - Private theCustomer as Customer

Object-Oriented Application Development Using VB.NET 15 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 –Note: More powerful of association is to invoke a series of methods. For example : - Cus1.getBoat( ).getLength( )

Object-Oriented Application Development Using VB.NET 16 Adding Functionality to the Boat Class Functionality of classes that have association relationships can be increased AssignBoatToCustomer custom method –Added in Boat Class. –Establishes the association between Boat and Customer in both directions in one step: - Public Sub AssignBoatToCustomer ( ByVal C1 As Customer) setCustomer ( C1) C1.setBoat(Me) End Sub

Object-Oriented Application Development Using VB.NET 17 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 18 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 Public Function TellAboutSelf( ) As String Return “Attributes of Boat” & theCustomer.TellAboutSelf( ) End Function

Object-Oriented Application Development Using VB.NET 19 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 20 Associating Docks and Slips: A One-to-Many Association Relationship To implement one-to-one association relationship between Slip and Dock –Use the same 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 21 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 22 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 –Ex: Private slips as ArrayList

Object-Oriented Application Development Using VB.NET 23 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 Ex: slips = New ArrayList( ) GetSlips Public Function GetSlips( ) As ArrayList Return slips End Function

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

Object-Oriented Application Development Using VB.NET 25 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 Private theDock As DocK –Accessor methods for the Dock reference attribute GetDock SetDock

Object-Oriented Application Development Using VB.NET 26 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 (Mandatory Relation) Invokes the slip’s AddSlipToDock method –AddSlipToDock method establishes the association in both directions by Public Sub AddSlipToDock( ByVal aDock As Dock) aDock.addSlip(Me) theDock. addSlip(Me) setDock(aDock) End Sub A TellAboutSelf method returns information about the slip & the slip’s dock.

Object-Oriented Application Development Using VB.NET 27 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, and SetBoat) –Modifications to the Boat class A Slip reference attribute Accessor methods (GetSlip, and SetSlip) AssignBoatToSlip method to establish the relation when needed. –Because of the relation between boat & slip is optional, there is no a slip, or boat parameter passed to the constructor methods.

Object-Oriented Application Development Using VB.NET 28 Adding the Boat and Customer Classes to the Slip Example If you get a Customer reference, you Can navigate to find: - The customer’s boat The boat’s slip The slip’s dock If you get a Dock reference, you Can navigate to Each slip The slip’s boat The customer who owns the boat

Object-Oriented Application Development Using VB.NET 29 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 30 Creating and Using an Association Class – Lease Modifications to the Lease superclass –A Slip reference attribute Private theSlip As Slip –A Customer reference attribute Private theCustomer As Customer –Accessor methods Both DailyLease & AnnualLease classes –Inherit the association between Lease and Slip Lease and Customer Modifications to the Customer class –A Lease reference attribute Private theLease As Lease –Accessor methods

Object-Oriented Application Development Using VB.NET 31 Creating and Using an Association Class – Lease Modifications to the Slip class –A Lease reference attribute Private theLease As Lease –Accessor methods –LeaseAnnualSlip method to instantiate Annual Lease Object. Public Sub LeaseAnnualSlip(ByVal aCus As Customer, _ ByVal startDate As DateTime, ByVal isPM As Boolean ) theLease = New AnnualLease(startDate, slipWidth, isPM) aCus.setLease(theLease) theLease.setSlip(Me) theLease.setCustomer(aCus) End Sub