DOC PREVIEW
CU-Boulder CSCI 5448 - Object Fundamentals Part Two

This preview shows page 1-2-3-18-19-37-38-39 out of 39 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Object Fundamentals Part Two Kenneth M Anderson University of Colorado Boulder CSCI 4448 5448 Lecture 3 09 01 2009 1 Lecture Goals Continue our tour of the basic concepts terminology and notations for object oriented analysis design and programming Some material for this lecture is drawn from Head First Java by Sierra Bates O Reilly 2003 2 Overview Objects Classes Relationships Inheritance Association Aggregation Composition Qualification Interfaces Ken s Corner Multiple Inheritance 3 Objects I OO Techniques view software systems as being composed of objects Objects have state aka attributes behavior aka methods or services We would like objects to be highly cohesive have a single purpose make use of all features loosely coupled be dependent on only a few other classes 4 Objects II Objects interact by sending messages to one another Object A sends a message to Object B to request that it perform a task When the task is complete B may pass a value back to A Note sometimes A B that is an object can send a message to itself Sometimes messages can be rerouted invoking a method defined in class A may be rerouted to an overridden version of that method in subclass B And invoking a method on an object of class B may invoke an inherited version of that method defined by superclass A 5 Objects III In response to a message an object may update its internal state retrieve a value from its internal state create a new object or set of objects delegate part or all of the task to some other object As a result objects can be viewed as members of various object networks Objects in an object network aka collaboration work together to perform a task for their host application 6 Objects IV UML notation Objects are drawn as rectangles with their names and types underlined Ken Person The name of an object is optional The type however is required Person Note the colon is not optional It s another clue that you are talking about an object not a class 7 Objects V Objects that know about each other have lines drawn between them This connection has many names the three most common are object reference reference link Messages are sent across links Links are instances of associations defined on slide 16 8 Objects Example t i s Ken Person Skippy Dog feed Felix Cat 9 Classes I A class is a blueprint for an object The blueprint specifies the attributes aka instance variables and methods of the class attributes are things an object of that class knows methods are things an object of that class does An object is instantiated created from the description provided by its class Thus objects are often called instances 10 Classes II An object of a class has its own values for the attributes of its class For instance two objects of the Person class can have different values for the name attribute In general each object shares the implementation of a class s methods and thus behave similarly When a class is defined its developer provides an implementation for each of its methods Thus object A and B of type Person each share the same implementation of the sleep method 11 Classes III Classes can define class wide aka static attributes and methods A static attribute is shared among a class s objects That is all objects of that class can read write the static attribute A static method does not have to be accessed via an object you invoke static methods directly on a class Static methods are often used to implement the notion of library in OO languages it doesn t make sense to have multiple instances of a Math class each with their own sin method We will see uses for static attributes and methods throughout the semester 12 Classes by Analogy Address Book Each card in an address book is an instance or object of the AddressBookCard class Each card has the same blank fields attributes You can do similar things to each card each card has the same set of methods The number of cards in the book is an example of a static attribute Sorting the cards alphabetically is an example of a static method 13 Classes IV UML Notation Classes appear as rectangles with multiple parts The first part contains its name defines a type The second part contains the class s attributes The third part contains the class s methods Song artist title play 14 Relationships Inheritance Classes can be related in various ways One class can extend another aka inheritance notation an open triangle points to the superclass As we learned last time the subclass can add behaviors or override existing ones Animal food type location makeNoise eat roam Hippo makeNoise eat submerge 15 Relationships Association One class can reference another aka association notation straight line This notation is a graphical shorthand that each class contains an attribute whose type is the other class Zoo Zoo Hippo ourHippo addAnimal addAnimal shortcut for Hippo Hippo Zoo myZoo makeNoise eat makeNoise eat 16 Multiplicity Associations can indicate the number of instances involved in the relationship this is known as multiplicity An association with no markings is one to one An association can also indicate directionality Examples on next slide 17 Multiplicity Examples A A A A A A 1 1 1 1 2 5 B One B with each A one A with each B B Same as above B Zero or more Bs with each A one A with each B B Zero or more Bs with each A ditto As with each B B Two to Five Bs with each A one A with each B B Zero or more Bs with each A B knows nothing about A 18 Multiplicity Example 1 A 2 5 B A B B A B B B 19 Relationships whole part Associations can also convey semantic information about themselves In particular aggregations indicate that one object contains a set of other objects think of it as a whole part relationship between a class representing a group of components a class representing the components Notation aggregation is indicated with a white diamond attached to the class playing the container role 20 Example Aggregation Aggregation Composition Crate Book Composition will be defined on the next slide Bottle Section Chapter Note aggregation and composition relationships change the default multiplicity of associations instead of one to one you should assume one to many 21 Semantics of Aggregation Aggregation relationships are transitive if A contains B and B contains C then A contains C Aggregation relationships are asymmetric If A contains B then B does not contain A A variant of aggregation is composition which adds the property of existence dependency if A composes B then if A is deleted B is


View Full Document

CU-Boulder CSCI 5448 - Object Fundamentals Part Two

Documents in this Course
Django

Django

42 pages

ENRS

ENRS

30 pages

PhoneGap

PhoneGap

22 pages

Load more
Download Object Fundamentals Part Two
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object Fundamentals Part Two and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object Fundamentals Part Two 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?