Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Bennett chap 4


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Bennett chap 4

  1. 1. 03/12/2001 1Chap. 4What Is Object-Orientation?Object Oriented Systems Analysis and DesignUsing UML, (3rd Edition), McGraw Hill
  2. 2. 2In This Lecture You Will Learn:In This Lecture You Will Learn:The fundamental concepts of object-orientationThe justifications for an object-orientedapproach
  3. 3. 3Basic ConceptsBasic ConceptsThe main concepts introduced here are:– Objects, Classes and Instances– Object State– Generalization and Specialization– Message-passing and Encapsulation– Polymorphism
  4. 4. 4ObjectsObjectsAn object is:“an abstraction of something in aproblem domain, reflecting thecapabilities of the system to– keep information about it,– interact with it,– or both.”Coad and Yourdon (1990)
  5. 5. 5AbstractionAbstractionA form of representation that includesonly what is important or interestingfrom a particular viewpoint– Map : never shows detail of the territoryRoad maps : showing roads and placesGeological maps : showing rocks and surfaces
  6. 6. 6ObjectsObjects“Objects have state, behaviour andidentity.”Booch (1994)State: the condition of an object at anymoment, affecting how it can behaveBehaviour: what an object can do, howit can respond to events and stimuliIdentity: each object is unique
  7. 7. 7Examples of ObjectsExamples of ObjectsObjectA person. ‘Hussain Pervez.’ Speak, walk, read.Studying, resting,qualified.A shirt.My favourite buttonwhite denim shirt.Shrink, stain, rip. Pressed, dirty,worn.A sale. Sale no #0015,18/05/05.Earn loyalty points. Invoiced,cancelled.Identity Behaviour StateA bottle ofketchup.This bottle ofketchup.Spill in transit. Unsold, opened,empty.
  8. 8. 8Class and InstanceClass and InstanceAll objects are instances of some classClass:A description of a set of objects withsimilar– features (attributes, operations, links);– semantics;– constraints (e.g. when and whether an object canbe instantiated).An abstract description for the specifiedlogical similarities between those objectsOMG (2004)
  9. 9. 9Class and InstanceClass and InstanceAn object is an instance of some classSo, instance = object– but also carries connotations of the class towhich the object belongsInstances of a class are similar in their:– Structure: what it knows, what informationit holds, what links it has to other objects– Behaviour: what an object can do
  10. 10. 10Information structuresInformation structuresfor two classesfor two classesClass Characteristics Class CharacteristicsStaff NameStaff numberStart dateClient NameAddressPhone numberFax numberEmail address
  11. 11. 11Generalization andGeneralization andSpecializationSpecializationClassification is hierarchic in natureFor example, a person may be anemployee, a customer, a supplier of aserviceAn employee may be paid monthly,weekly or hourlyAn hourly paid employee may be adriver, a cleaner, a sales assistant
  12. 12. 12Specialization HierarchySpecialization HierarchyPersonEmployee Customer SuppliermonthlypaidweeklypaidhourlypaidDriver Cleaner SalesassistantMore general(superclasses)More specialized(subclasses)
  13. 13. 13Generalization andGeneralization andSpecializationSpecializationSpecialization adds additionalinformation:Personnamedate of birthgendertitleHourlyPaidDriverstartDatestandardRateovertimeRatelicenceTypeGeneral (superclass) Specialized (subclass)
  14. 14. 14InheritanceInheritanceThe whole description of a superclass appliesto all its subclasses, including:– Information structure (including associations)– BehaviourOften known loosely as inheritanceInheritance is how an O-O programminglanguage implements generalization /specialization
  15. 15. 15MessageMessage--passingpassingSeveral objects may collaborate to fulfileach system actionThese objects communicate by sendingeach other messagesA way of insulating each object fromthe need to ‘know’ any of the internaldetails of other objects.
  16. 16. 16MessageMessage--passing andpassing andEncapsulationEncapsulationMessage from another objectrequests a service.Operation called only via validoperation signature.Data accessed only byobject’s own operations.An object’s datais hidden(encapsulated).An outer layer ofoperation signatures……gives access to middlelayer of operations……which can accessinner core of data‘Layers of an onion’model of an object:
  17. 17. 17PolymorphismPolymorphismAn ability to appear as many formsPolymorphism allows one message to be sent toobjects of different classes– Each object responds to the message in a different waySending object need not know what kind of objectwill receive the messageEach receiving object knows how to respondappropriatelyFor example, a ‘Calculate Pay’ operation
  18. 18. 18An Example of PolymorphismAn Example of Polymorphism(Overriding)(Overriding):MonthlyPayPrint:FullTimeEmployee:PartTimeEmployee:TempEmployeeFixed monthlyamount depends onlyon employee gradeVariable monthlyamount depends ongrade and hoursFixed monthly amountdepends on grade, butno pension deductionsPay Clerk1: getTotalPay()2a: calculatePay()2b: calculatePay()2c: calculatePay()
  19. 19. 19Advantages of OAdvantages of O--OOCan save effort– Reuse of generalized components cutswork, cost and timeCan improve software quality– Encapsulation increases modularity– Sub-systems less coupled to each other– Better translations between analysis anddesign models and working code