Download presentation
Presentation is loading. Please wait.
1
03/12/2001 © Bennett, McRobb and Farmer 2002 1 What Is Object-Orientation? Based on Chapter 4 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using UML, (2 nd Edition), McGraw Hill, 2002.
2
06 January 2002 © Bennett, McRobb and Farmer 2002 2 In This Lecture You Will Learn: n The fundamental concepts of object- orientation n The justifications for an object-oriented approach
3
06 January 2002 © Bennett, McRobb and Farmer 2002 3 Basic Concepts n The main concepts introduced here are: –Objects, Classes and Instances –Object State –Generalization and Specialization –Message-passing and Encapsulation –Polymorphism
4
06 January 2002 © Bennett, McRobb and Farmer 2002 4 Objects An object is: “an abstraction of something in a problem domain, reflecting the capabilities of the system to –keep information about it, –interact with it, –or both.” Coad and Yourdon (1990)
5
06 January 2002 © Bennett, McRobb and Farmer 2002 5 Objects “Objects have state, behaviour and identity.” Booch (1994) n State: the condition of an object at any moment, affecting how it can behave n Behaviour: what an object can do, how it can respond to events and stimuli n Identity: each object is unique
6
06 January 2002 © Bennett, McRobb and Farmer 2002 6 Examples of Objects Object A person. ‘Hussain Pervez.’ Speak, walk, read. Studying, resting, qualified. A shirt. My favourite button white denim shirt. Shrink, stain, rip. Pressed, dirty, worn. A sale. Sale no #0015, 16/06/02. Earn loyalty points.Invoiced, cancelled. IdentityBehaviourState A bottle of ketchup. This bottle of ketchup. Spill in transit.Unsold, opened, empty.
7
06 January 2002 © Bennett, McRobb and Farmer 2002 7 Class and Instance n All objects are instances of some class n Class: “a description of a set of objects with similar –attributes, –operations, –methods –relationships and semantics.” OMG (2001)
8
06 January 2002 © Bennett, McRobb and Farmer 2002 8 Class and Instance “The purpose of a class is to declare a collection of methods, operations and attributes that fully describe the structure and behaviour of objects.” OMG (2001) n Structure: what an object knows, information that it holds n Behaviour: what an object can do
9
06 January 2002 © Bennett, McRobb and Farmer 2002 9 Class and Instance An object is: “an instance that originates from a class, it is structured and behaves according to its class.” OMG (2001)
10
06 January 2002 © Bennett, McRobb and Farmer 2002 10 Generalization and Specialization n Classification is hierarchic in nature n For example, a person may be an employee, a customer, a supplier of a service n An employee may be paid monthly, weekly or hourly n An hourly paid employee may be a driver, a cleaner, a sales assistant
11
06 January 2002 © Bennett, McRobb and Farmer 2002 11 Specialization Hierarchy Person EmployeeCustomer Supplier monthly paid weekly paid hourly paid DriverCleaner Sales assistant More general (superclasses) More specialized (subclasses)
12
06 January 2002 © Bennett, McRobb and Farmer 2002 12 Generalization and Specialization n More general bits of description are abstracted out from specialized classes: Person Name Date of birth Gender Title HourlyPaidDriver StartDate StandardRate OvertimeRate LicenceType General (superclass)Specialized (subclass)
13
06 January 2002 © Bennett, McRobb and Farmer 2002 13 Inheritance n The whole description of a superclass applies to all its subclasses, including: –Information structure –Behaviour n Often known loosely as inheritance n (Actually, inheritance is the facility in an O-O language that implements generalization / specialization)
14
06 January 2002 © Bennett, McRobb and Farmer 2002 14 Message-passing n Several objects may collaborate to fulfil each system action n “Record CD sale” could involve: –A CD stock item object –A sales transaction object –A sales assistant object n These objects communicate by sending each other messages
15
06 January 2002 © Bennett, McRobb and Farmer 2002 15 Message-passing and Encapsulation Message from another object requests a service. Operation called only via valid operation signature. Data accessed only by object’s own operations. An object’s data is hidden (encapsulated). ‘Layers of an onion’ model of an object: An outer layer of operation signatures… …gives access to middle layer of operations… …which can access inner core of data
16
06 January 2002 © Bennett, McRobb and Farmer 2002 16 Polymorphism n Polymorphism allows one message to be sent to objects of different classes n Sending object need not know what kind of object will receive the message n Each receiving object knows how to respond appropriately n For example, a ‘resize’ operation in a graphics package
17
06 January 2002 © Bennett, McRobb and Farmer 2002 17 Polymorphism in Resize Operations Campaign title campaignStartDate campaignFinishDate getCampaignAdverts() addNewAdvert() > Campaign title campaignStartDate campaignFinishDate getCampaignAdverts() addNewAdvert() >
18
06 January 2002 © Bennett, McRobb and Farmer 2002 18 Advantages of O-O n Can save effort –Reuse of generalized components cuts work, cost and time n Can improve software quality –Encapsulation increases modularity –Sub-systems less coupled to each other –Better translations between analysis and design models and working code
19
06 January 2002 © Bennett, McRobb and Farmer 2002 19 Summary In this lecture you have learned about: n The fundamental concepts of O-O –Object, class, instance –Generalization and specialization –Message-passing and polymorphism n Some of the advantages and justifications of O-O
20
06 January 2002 © Bennett, McRobb and Farmer 2002 20 References n Coad and Yourdon (1990) n Booch (1994) n OMG (2001) (For full bibliographic details, see Bennett, McRobb and Farmer)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.