Software System EngineeringSlide 2Slide 3ObjectsClassesAttributesObject Behavior (1)Object Behavior (2)Message (1)Message (2)Methods vs. MessagesEncapsulationClass HierarchyInheritanceDynamic InheritanceMultiple InheritancePolymorphismAssociationsConsumer-Producer AssociationAggregationsDiscussion Questions© M.E. Fayad 2000 -- 2006SJSU -- CMPESoftware System EngineeringDr. M.E. Fayad, ProfessorComputer Engineering Department, Room #283I College of EngineeringSan José State UniversityOne Washington SquareSan José, CA 95192-0180 http://www.engr.sjsu.edu/~fayad© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S2 OO Concepts2Lesson 5:Object-Oriented Concepts© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S3 OO Concepts Lesson ObjectivesObjectives3 Understand OO concepts Explore OO modelsObjectsClassesMethodsAssociationsetc…© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S4 OO Concepts4 ObjectsWhen developing OO application, two basic questions:–What objects does the application need?–What are the characteristics of these objects–What functionality should these objects have?© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S5 OO Concepts5 ClassesObjects are grouped in classesClasses are used to distinguish one type of object from anotherA class is a set of objects that share some common structures and behaviors–Each object is an instance of a classIn an OO system, behavior of an object is defined by its class© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S6 OO Concepts6 AttributesAttributes are properties of an object–E.g., color, cost, make, and model of a car objectProperties represent the state of an object© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S7 OO Concepts7 Object Behavior (1)Object behavior is described in procedures, interfaces or methodsA method is defined for a class and can access the internal state of an object of that class to perform some operation© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S8 OO Concepts8 Object Behavior (2)Behavior denotes the collection of methods that abstractly describes what an object is capable of doing –Each method defines and describes a particular behavior of an objectObjects take responsibility of their own behavior–E.g., an employee object knows how to compute its salary© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S9 OO Concepts9 Message (1)Objects perform operations in response to messagesMessage is different from a subroutine call–Different objects can respond to the same message in different ways•e.g., cars, motorcycles, and bicycles will all respond to a stop message -- but differentlyA message has a name© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S10 OO Concepts10 Message (2)An object understands a message when it can match the message to a method that has the same name as the messageMessage differs from function–Function says how to do something–Message says what to do© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S11 OO Concepts11 Methods vs. MessagesMessage is the instructionMethod is the implementationE.g., making French onion soup–Telling someone to make a Greek Salad is the message–The way the Greek Salad is prepared is the method–The Greek Salad is the object© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S12 OO Concepts12 EncapsulationEncapsulation is a form of information hidingAn object encapsulates the data and methods–User cannot see the inside of the object “capsule,” but can use the object by calling the object’s methods–No object can operate directly on another object’s data -- Important Point.© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S13 OO Concepts13 Class HierarchyAn object-oriented system organizes classes into a subclass-superclass hierarchy–superclass = base class or ABC class–subclass = derived class or concrete classAt the top of the class hierarchy are the most general classes and at the bottom are the most specific© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S14 OO Concepts14 InheritanceInheritance allows classes to share and reuse behaviors and attributesA subclass inherits all of the properties and methods defined in its superclass© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S15 OO Concepts15 Dynamic InheritanceAllows objects to change and evolve over timeSuperclasses (or base classes) provide properties and attributes for objects–Changing superclasses changes the properties and attributes of a classAbility to add, delete, or change parents from objects (or classes) at run time© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S16 OO Concepts16 Multiple InheritanceA class can inherit its state (attributes) and behaviors from more than one superclassExample: a utility vehicle inherits attributes from both the Car and Truck classes© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S17 OO Concepts17 PolymorphismThe same operation may behave differently on different classesExample: in a payroll system, manager, office worker, and production worker are objects that respond to the compute payroll message -- but differently© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S18 OO Concepts18 AssociationsAssociation represents the relationship between objects and classesAssociations are bidirectional.Associations have cardinality.–How many instances of one class may relate to a single instance of an associated class© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S19 OO Concepts19 Consumer-Producer AssociationSpecial form of association–Also known as client-server association or a use relationshipViewed as a one-way interaction–One object requests the service of another object© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S20 OO Concepts20 AggregationsAll objects, except the most basic ones, are composed of and may contain other objectsE.g., a car object is an aggregation of engine, seat, wheels, and other objects© M.E. Fayad 2000 -- 2006SJSU -- CmpE M.E. Fayad L3-1-S21 OO Concepts21 Discussion QuestionsWhat are the differences between inheritance and aggregation?T/F–Use relationship is an aggregation.–Aggregation is a special form of
View Full Document