![Page 1: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/1.jpg)
Object-oriented Design and Programming
CS 2210: SW Development Methods
•Reading: Chapter 2 of MSD text– Section 2.3.2 on UML: look at class diagrams but ignore the rest for now
![Page 2: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/2.jpg)
This Unit Overview
• Review OO, objects, classes• Object identity, equality and Java• Intro to abstraction and inheritance• Class identification and modeling• Modeling object interaction• More Java details on classes etc.
– inheritance, abstract classes, types
![Page 3: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/3.jpg)
What’s OO All About?
• At a very high level, programs are:– procedures operating on– data-objects
• The “old” view sometimes called procedural– Procedures are the starting point– Access data through parameters, shared
values– Only approach for languages like C, Pascal
• A system is: a hierarchy of procedure calls
![Page 4: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/4.jpg)
The OO Approach
• Object-oriented:– Emphasis on the data-objects first
• Data encapsulation
– Associate procedures with the data-objects• Procedural encapsulation• Call operations on data-objects, or• Send a data-object a message
• A system is: a group of collaborating objects
![Page 5: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/5.jpg)
What’s an Object?
• Grady Booch’s definition: an object has: state, behavior, identity
• State– encapsulates data (e.g. fields in Java
objects)– contains relationships with other objects
(e.g. references to other objects)
![Page 6: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/6.jpg)
What’s an Object? (2)
• Behavior– Responds to operations, messages (e.g.
Java method calls on that object)– Interacts with other objects to
accomplish a task
![Page 7: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/7.jpg)
What’s an Object? (3)
• Identity– Simple idea, but…
• Are two objects the same? Or are they equal?– Reference variables in Java, C++, etc.– Identity means: refers to the same
object– Book calls this: name equivalence
![Page 8: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/8.jpg)
Object Equality
• Equality: perhaps two things can be different things, but equal according to some problem-defined condition– E.g. two Course objects: equal if same
courseID field (let’s say)– Book’s term: content equivalence
![Page 9: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/9.jpg)
For objects, do you think == tests for:
1. Name equivalence2. Content equivalence3. Neither one4. Both
![Page 10: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/10.jpg)
Do you think equals() returns true for:
1. Name equivalence2. Content equivalence3. Neither one4. Either
Example: x.equals(y) is true means what about x and y?
![Page 11: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/11.jpg)
Java and Object Equivalence
• Java supports both. You must understand them both!– If not: see slides at the end of this deck
• name equivalence: operator ==– E.g. x==y means “do x and y reference
the same (one) object”?• method boolean equals()
– E.g. x.equals(y) means “do x and y stored the same values to make them content equivalent”?
![Page 12: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/12.jpg)
Classes
• So far we’ve just talked about objects• We note that many objects are a
“type of” the same kind of thing– The same “abstraction”– E.g. 1, 2, 7 and 10 – whole numbers– E.g. 1, 3.5, 25, pi – numbers– Bob, Sally, Joe – Students
• But, they are Persons too, aren’t they?
– cs2110, cs2102, engr1620 – Courses
![Page 13: Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section 2.3.2 on UML: look at class diagrams but](https://reader036.vdocuments.us/reader036/viewer/2022083006/56649f355503460f94c5262d/html5/thumbnails/13.jpg)
Classes, Type
• Classes define a set of objects with the same properties (state, behavior)
• A class definition serves as a “cookie cutter” for creating new objects– Instantiation of an object of a certain class– In Java, we do this with new and a constructor
is called– Creates an individual object, also called an
instance
• Variables and data objects have a type– What the rules are for that object– An object’s class is one form of object-type