03/12/2001 1Chap. 4What Is Object-Orientation?Object Oriented Systems Analysis and DesignUsing UML, (3rd Edition), McGraw Hill
2In This Lecture You Will Learn:In This Lecture You Will Learn:The fundamental concepts of object-orientationThe justifications for an object-orientedapproach
3Basic ConceptsBasic ConceptsThe main concepts introduced here are:– Objects, Classes and Instances– Object State– Generalization and Specialization– Message-passing and Encapsulation– Polymorphism
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)
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
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
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.
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)
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
10Information structuresInformation structuresfor two classesfor two classesClass Characteristics Class CharacteristicsStaff NameStaff numberStart dateClient NameAddressPhone numberFax numberEmail address
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
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
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.
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:
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
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()
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
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.