Download presentation
Presentation is loading. Please wait.
1
Object Oriented Programming
Lecture 12 Object Oriented Programming Richard Gesick
2
Topics Identifying Classes & Objects Class Relationships “this”
Parameters Overloading Methods Operators
3
Identifying Classes & Objects
Identify potential classes within the specification Nouns
4
What Goes in the Class How do you decide what should be in the class
Data Methods
5
Class Relationships Classes can have various relationships to one another. Most common are: Dependency (“uses”) Aggregation (“has a”) Inheritance (“is a”)
6
Object Relationships Objects can have various types of relationships to each other A general association is sometimes referred to as a use relationship A general association indicates that one object (or class) uses or refers to another object (or class) in some way We could even annotate an association line in a UML diagram to indicate the nature of the relationship Author Book writes
7
Dependency One class dependent (uses) another class
Game uses ball, paddle Ship uses bullet Sometimes, a class depends on another instance of itself Is one date equal to another date? Is one picture equal to another picture?
8
Aggregation One class is “made up” of other classes
“has a” relationship Gameboard has a marble Deck has a card
9
Aggregation An aggregate object is an object that contains references to other objects For example, an Account object contains a reference to a String object (the owner's name) An aggregate object represents a has-a relationship A bank account has a name Likewise, a student may have one or more addresses
10
Aggregation in UML An aggregation association is shown in a UML class diagram using an open diamond at the aggregate end StudentBody + Main (args : String[]) : void + ToString() : String 1 2 Student - firstName : String - lastName : String - homeAddress : Address - schoolAddress : Address - streetAddress : String - city : String - state : String - zipCode : long Address
11
UML Diagrams classes are represented with boxes that contain three compartments: The top compartment contains the name of the class. The middle compartment contains the attributes of the class. The bottom compartment contains the methods and properties
12
UML Diagrams Player - name:string -money:float -health: int +Player():
+Buy(float):void +GetName():string +Name:string {property} +Money:float {property} +ToString():string
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.