Unformatted text preview:

Object FundamentalsPart TwoKenneth M. AndersonUniversity of Colorado, BoulderCSCI 4448/6448 — Lecture 3 — 09/02/20081Tuesday, September 2, 2008Lecture 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• But first!• Check out <http://www.google.com/googlebooks/chrome/index.html/>• for a unique take on documenting design decisions: comic book format• Google, one of the premier Internet companies, decided to announce its new Web browser by creating a comic book and sending it to people via postal mail (aka snail mail)!!!2Tuesday, September 2, 2008Overview• Objects• Classes• Relationships• Inheritance• Association• Aggregation/Composition• Qualification• Interfaces• Ken’s Corner: Multiple Inheritance3Tuesday, September 2, 2008Objects (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 classes4Tuesday, September 2, 2008Objects (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 A5Tuesday, September 2, 2008Objects (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 application6Tuesday, September 2, 2008Objects (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 class7Tuesday, September 2, 2008Objects (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)8Tuesday, September 2, 2008Objects (Example)Skippy: DogFelix: CatKen: Personsit()feed()9Tuesday, September 2, 2008Classes (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 instances10Tuesday, September 2, 2008Classes (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() method11Tuesday, September 2, 2008Classes (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 semester12Tuesday, September 2, 2008Classes 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 method13Tuesday, September 2, 2008Classes (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 methodsplay()artisttitleSong14Tuesday, September 2, 2008Relationships: 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 Animallocationfood typeroam()eat()makeNoise()Hippoeat()makeNoise()submerge()15Tuesday, September 2, 2008Relationships: 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 classZooaddAnimal()Hippoeat()makeNoise()ZooaddAnimal()Hippo ourHipposhortcut forHippoeat()makeNoise()Zoo myZoo16Tuesday, September 2, 2008Multiplicity• 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 slide17Tuesday, September 2, 2008Multiplicity ExamplesA BOne B with each A; oneA with each BA B11Same as aboveA B*1Zero or more Bs with eachA; one A with each BA B**Zero or more Bs with eachA; ditto As with each BA B2..51A B*Two to Five Bs with eachA; one A with each


View Full Document

CU-Boulder CSCI 6448 - Object Fundamentals Part Two

Documents in this Course
Struts

Struts

12 pages

Adapter

Adapter

23 pages

Prototype

Prototype

16 pages

Weka

Weka

15 pages

qooxdoo

qooxdoo

16 pages

Django

Django

12 pages

Overview

Overview

22 pages

XNA

XNA

5 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?