2. Object Model Benefits of OO Development

2. Object Model Benefits of OO Development

2. Object Model Veennkkaattt SSuubbrraamaanniiiaam UML-1 Benefits Of OO Development • Models System using Objects • Small Semantic gap between reality & model • Understanding the system is easier • Modifications are localized Veennkkaattt SSuubbrraamaanniiiaam UML-2 Object-Oriented Paradigm Collection of Discrete Objects Data & Behavior OO Paradigm • Abstraction • Encapsulation • Hierarchy œ Inheritance hierarchy (—is-a“) œ Part of hierarchy (—has a“) • Polymorphism Veennkkaattt SSuubbrraamaanniiiaam UML-3 Abstraction —A simplified description ... of a system that emphasizes some of the system‘s details ... while suppressing others“ —An abstraction denotes the essential characteristics of an object that distinguish it from all other kind of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer“ Veennkkaattt SSuubbrraamaanniiiaam UML-4 Encapsulation • Information hiding • Interface - Implementation • Behavior & Data —Encapsulation is the process of compartmentalizingthe elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation“ Veennkkaattt SSuubbrraamaanniiiaam UML-5 What is an Object? • —Concept, abstraction, or thing with crisp boundary & meaning for a problem“ • An Object has state and behavior • Objects receive stimuli/messages & respond • Receiving a stimulus, Object may change state Examples: jullie dylan kim charlie charlie.fly() stimulus Veennkkaattt SSuubbrraamaanniiiaam UML-6 2hat is a Class? • Group of Objects with similar œproperties (attributes) œbehavior œrelationships to other objects œsemantics • Blueprints of Objects Parrot Example Girl Boy jullie kim dylan charlie Veennkkaattt SSuubbrraamaanniiiaam UML-7 Hierarchy —Hierarchy is a ranking of abstractions“ Inheritance : expresses —is-a“ or —Kind-of“ relationship • Extensibility & Reusability Part-of: expresses that object is an aggregate of another Veennkkaattt SSuubbrraamaanniiiaam UML-8 Polymorphism Hiding alternative procedures behind a Common Interface Send a Message to an object - Polymorphism guarantees that the correct/proper implementation is invoked. Sender does not know specific class of receiver Veennkkaattt SSuubbrraamaanniiiaam UML-9 Object Model • Captures static structure of system • Objects, relationships, attributes & operations • Most important • Intuitive graphic representation • Valuable for communication & documentation Veennkkaattt SSuubbrraamaanniiiaam UML-10 Objects • Decomposing problem into objects œ depends on judgement & nature of problem • No one correct representation • Objects have identity Veennkkaattt SSuubbrraamaanniiiaam UML-11 Class • Often appear as nounsin problem descriptions • Has semantic • Interpretation of semantics œ depends on application and matter of judgement • Each class may have zero, one or more objects • Each object knows it class Veennkkaattt SSuubbrraamaanniiiaam UML-12 Class Diagrams • Provide formal graphic notation for modeling • Concise, easy to understand, practical • Describes many possible instances Veennkkaattt SSuubbrraamaanniiiaam UML-13 Object Diagrams • Describes how set of objects relate • Useful for œ documenting test cases œ Clarification of complex class diagrams • Class Diagram corresponds to infinite set of object diagrams Veennkkaattt SSuubbrraamaanniiiaam UML-14 Notation for Classes & Objects (UML) Girl kelly b renda : Girl Boy d ylan Classes Objects Veennkkaattt SSuubbrraamaanniiiaam UML-15 Attributes • Data value held by objects of a class • Objects may have same/different values for attribute • Attribute name unique within a class • Adjectives often represent specific enumerated attribute values : —red car“ Veennkkaattt SSuubbrraamaanniiiaam UML-16 Attributes... • Attribute is a pure data value - not an object • Internal identifiers must not be shown as attributes • Show only important attributes Veennkkaattt SSuubbrraamaanniiiaam UML-17 Derived Attributes Base Attribute : œ primitive, not dependent on other attributes Derived Attribute : œ computing not considered to change state of an object œ dependent on base attributes œ may be stored or computed upon a query operation Example : Area of a circle, age of a person Veennkkaattt SSuubbrraamaanniiiaam UML-18 Attributes Notation className Girl -attrPrivate #attrProtected -name +attrPublic Underline in revised $attrStatic notation +dob /attrDerived /age: int -attrWType: int -attrWInitVal: double=0.0 Veennkkaattt SSuubbrraamaanniiiaam UML-19 Operations & Methods • Operation : Function that may be applied to or by objects • Same Operations applying to different classes: Polymorphic • Method is implementation of an operation for a class • Operation has a target object and may have arguments • Same operations on different classes should have œ same signature and consistent intent • Query Operation : Does not affect the state of object • Show only important methods Veennkkaattt SSuubbrraamaanniiiaam UML-20 Operations Notation className +publicMethod() Girl #protectedMethod() -privateMethod() +sing() $staticMethod() +methodWParam(int) +play() +methodWRetVal(): int Veennkkaattt SSuubbrraamaanniiiaam UML-21 Example with Attributes & Operations StopWatch -seconds +start() +stop() +reset() +getSeconds(): double Veennkkaattt SSuubbrraamaanniiiaam UML-22 Associations and Links • Link is physical or conceptual connection between objects • Link is an instance of an Association Example: Link : Susan is-wife-of Robert Julie is-wife-of John Association:Woman is-wife-of Man Associations and Links appear as Verbs Veennkkaattt SSuubbrraamaanniiiaam UML-23 Associations & Links... • Associations are bi-directional œmay be implemented as unidirectional • Implemented usually as pointers œ important not to think as pointers • Associations may be œone-to-one œone-to-many œmany-to-one œmany-to-many Veennkkaattt SSuubbrraamaanniiiaam UML-24 Ternary & High Order Associations Binary Association : Relates two classes Woman is-wife-of Man Ternary Association : Relates three classes Nancy is-daughter-of Susan and Robert n-ary Association : Relates n classes Higher Order Associations œ complicated to draw, implement and think œ try to avoid if possible Veennkkaattt SSuubbrraamaanniiiaam UML-25 Associations Notations Exactly One * Many 0..1 Directed Association Optional * 1..* One Or More 0..* Zero Or More 0..* 1..* Company employees Person employs worksFor Veennkkaattt SSuubbrraamaanniiiaam UML-26 Link Attributes & Association Classes • Attributes that belong to association of object rather than one object • Link Attributes belong in Association Classes • Ex: Salary received by Employee from Company • In an one-to-one association you may try to make it attribute of one of the objects œLeads to extensibility problems Veennkkaattt SSuubbrraamaanniiiaam UML-27 Association Class Notation Person * * Company Employment salary:double Veennkkaattt SSuubbrraamaanniiiaam UML-28 Role Names • Name given to either end of an association • Helps to navigate from one object to related objects wife husband Woman 0..1 married 0..1 Man • Helps clarify when two classes have several associations between them wife husband 0..1 married 0..1 Woman Man * 1 daughter children father Veennkkaattt SSuubbrraamaanniiiaam UML-29 Qualifiers • Distinguishes among set of associated objects • Models associative arrays, dictionaries • Qualifiers may be wrongly modeled as attribute of associated class Student GradeList * * code Unqualified 1 GradeList code * Student Qualified Veennkkaattt SSuubbrraamaanniiiaam UML-30 Aggregation & Composition Aggregation: • Part-of or part-whole relationship (by reference) • Example : Car has Engine and Transmission • Assembly of objects with aggregate and component parts • Component existence may or may not depend on aggregate Veennkkaattt SSuubbrraamaanniiiaam UML-31 Aggregation & Composition... Composition: • Part belongs to only one whole (by Value) • Part lives and dies with the whole • Whole cannot replace the part Veennkkaattt SSuubbrraamaanniiiaam UML-32 Aggregation/ Composition Notation Aggregation Has By Value Has By Reference Engine Vehicle +drive() VIN Veennkkaattt SSuubbrraamaanniiiaam UML-33 Aggregation / Composition Example Person brain Composition Aggregation Car Veennkkaattt SSuubbrraamaanniiiaam UML-34 Inheritance • Models is-a relationship • Relationship between a class and its refined versions • Superclass or Base class • Subclass or Derived class • Inheritance is transitive • Discriminator : The property being abstracted by a particular inheritance • Breath Vs. Depth of inheritance Veennkkaattt SSuubbrraamaanniiiaam UML-35 Inheritance Notation Generalization Superclass Vehicle +drive() Subclass1 Subclass2 Car Truck -sunRoof Veennkkaattt SSuubbrraamaanniiiaam UML-36 Inheritance Example Child Animal Girl Boy Dog Cat Veennkkaattt SSuubbrraamaanniiiaam UML-37 Grouping Mechanism : Package • Grouping classes together into higher-level units • Package diagram with dependency • Dependency between packages exists if œ class in one package depends on a class in the other œ definition change of one package may change other Veennkkaattt SSuubbrraamaanniiiaam UML-38 Package Notation componentName VehicleComponent Veennkkaattt SSuubbrraamaanniiiaam Accessories EngineCompoUnMenLt-39 Aggregation Vs. Association • Special form of Association • Confusing • Aggregation represents —part-of“ relationship • Some operations on whole automatically applied to its parts • Aggregate is asymmetric : part is subordinate

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    28 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us