Presentation is loading. Please wait.

Presentation is loading. Please wait.

What Is Object-Orientation?

Similar presentations


Presentation on theme: "What Is Object-Orientation?"— Presentation transcript:

1 What Is Object-Orientation?
Based on Chapter 4 of Bennett, McRobb and Farmer: Object Oriented Systems Analysis and Design Using UML, (4th Edition), McGraw Hill, 2010. © 2010 Bennett, McRobb and Farmer

2 In This Lecture You Will Learn:
The fundamental concepts of object-orientation, including: Objects and classes Generalization, specialization and inheritance Information hiding and message passing The justifications for an object-oriented approach Note for lecturers: these slides do not include coverage of how O-O is used in practice. Extra material could be usefully added to show: practical examples of O-O systems facilities of modern O-O languages typical applications and also limitations of O-O. © 2010 Bennett, McRobb and Farmer

3 © 2010 Bennett, McRobb and Farmer
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) © 2010 Bennett, McRobb and Farmer

4 © 2010 Bennett, McRobb and Farmer
Objects “Objects have state, behaviour and identity.” Booch (1994) State: the condition of an object at any moment, affecting how it can behave Behaviour: what an object can do, how it can respond to events and stimuli Identity: each object is unique © 2010 Bennett, McRobb and Farmer

5 © 2010 Bennett, McRobb and Farmer
Examples of Objects Object Identity Behaviour State Studying, resting, qualified. A person. ‘Hussain Pervez.’ Speak, walk, read. My favourite button white denim shirt. A shirt. Shrink, stain, rip. Pressed, dirty, worn. A sale. Sale no #0015, 18/05/05. Earn loyalty points. Invoiced, cancelled. A useful exercise for the class would be to suggest other behaviours and states for these objects, and to describe: How external events and object behaviour can both result in a change of state How state restricts the possible behaviours of an object A bottle of ketchup. This bottle of ketchup. Spill in transit. Unsold, opened, empty. © 2010 Bennett, McRobb and Farmer

6 © 2010 Bennett, McRobb and Farmer
Class and Instance All objects are instances of some class A Class is a description of a set of objects with similar: features (attributes, operations, links); semantics; constraints (e.g. when and whether an object can be instantiated). OMG (2009) We don’t go into relationships and semantics at all here. Nor do we discuss attributes, operations and methods in any detail. All will be covered more extensively in later material, but lecturers may wish to add more explanation here. © 2010 Bennett, McRobb and Farmer

7 © 2010 Bennett, McRobb and Farmer
Class and Instance An object is an instance of some class So, instance = object but also carries connotations of the class to which the object belongs Instances of a class are similar in their: Structure: what they know, what information they hold, what links they have to other objects Behaviour: what they can do © 2010 Bennett, McRobb and Farmer

8 Generalization and Specialization
Classification is hierarchic in nature For example, a person may be an employee, a customer, a supplier of a service An employee may be paid monthly, weekly or hourly An hourly paid employee may be a driver, a cleaner, a sales assistant © 2010 Bennett, McRobb and Farmer

9 Specialization Hierarchy
More general (superclasses) Person Employee Customer Supplier monthly paid weekly paid hourly paid It would be a useful class exercise to: add more detail to other parts of this hierarchy to suggest ways in which the various subclasses differ from each other in behaviour and structure. More specialized (subclasses) Driver Cleaner Sales assistant © 2010 Bennett, McRobb and Farmer

10 Generalization and Specialization
More general bits of description are abstracted out from specialized classes: SystemsAnalyst Driver name employee-no startDate monthlySalary grade name employee-no startDate standardHourlyRate overtimeRate licenceType © 2010 Bennett, McRobb and Farmer

11 Specialized (subclasses)
SystemsAnalyst General (superclass) monthlySalary grade Employee name employee-no startDate Driver standardHourlyRate overtimeRate licenceType © 2010 Bennett, McRobb and Farmer

12 © 2010 Bennett, McRobb and Farmer
Inheritance The whole description of a superclass applies to all its subclasses, including: Information structure (including associations) Behaviour Often known loosely as inheritance (But actually inheritance is how an O-O programming language implements generalization / specialization) © 2010 Bennett, McRobb and Farmer

13 © 2010 Bennett, McRobb and Farmer
SystemsAnalyst monthlySalary grade Employee name employee-no startDate Driver standardHourlyRate overtimeRate licenceType All characteristics of the superclass are inherited by its subclasses © 2010 Bennett, McRobb and Farmer

14 © 2010 Bennett, McRobb and Farmer
Instances of each subclass include the characteristics of the superclass (but not usually shown like this on diagrams) :SystemsAnalyst name employee-no startDate monthlySalary grade :Driver name employee-no startDate standardHourlyRate overtimeRate licenceType © 2010 Bennett, McRobb and Farmer

15 © 2010 Bennett, McRobb and Farmer
Message-passing Several objects may collaborate to fulfil each system action “Record CD sale” could involve: A CD stock item object A sales transaction object A sales assistant object These objects communicate by sending each other messages I have called this a ‘system action’ because the proper term ‘use case’ may not yet have been introduced. It would probably be useful to add a forward pointer to the lecture where use cases are discussed. A possible exercise would be for the class to discuss and suggest how these objects might participate in the use case, and what operations and attributes are implied by the interaction. © 2010 Bennett, McRobb and Farmer

16 Message-passing and Encapsulation
Message from another object requests a service. Operation signature is an interface through which an operation can be called. Operations are located within an object. Data used by an operation is located in the object too ‘Layers of an onion’ model of an object: An outer layer of operation signatures… …gives access to middle layer of operations… This is the only mention of encapsulation in these slides. It may be worth adding more material and spending a little time explaining the significance of this concept. …which access an inner core of data © 2010 Bennett, McRobb and Farmer

17 Information Hiding: a strong design principle
Message from another object requests a service. Operations can only be called by message with valid operation signature. Only object’s own operations can access its data. Representation of data is hidden inside object ‘Layers of an onion’ model of an object: Only the outer layer is visible to other objects… …and it is the only way to access operations… …which are the only way to access the hidden data © 2010 Bennett, McRobb and Farmer

18 © 2010 Bennett, McRobb and Farmer
Polymorphism Polymorphism allows one message to be sent to objects of different classes Sending object need not know what kind of object will receive the message Each receiving object knows how to respond appropriately For example, a ‘resize’ operation in a graphics package The ‘resize’ example will need more explanation than this. What I had in mind was the way that circles, rectangles, bitmaps, groups of objects, etc will all need their own distinct methods to implement the operation. However, from the perspective of a user (or indeed a boundary object) all are called in the same way. The class could be asked to suggest other examples of polymorphism, and to explain what is polymorphic about each. © 2010 Bennett, McRobb and Farmer

19 Polymorphism in Resize Operations
Campaign title campaignStartDate campaignFinishDate getCampaignAdverts() addNewAdvert() <<entity>> © 2010 Bennett, McRobb and Farmer

20 © 2010 Bennett, McRobb and Farmer
Advantages of O-O Can save effort Reuse of generalized components cuts work, cost and time Can improve software quality Encapsulation increases modularity Sub-systems less coupled to each other Better translations between analysis and design models and working code This slide covers the point only in bare outline. Extra material could usefully be added to show the advantages of and justifications for O-O in more detail. © 2010 Bennett, McRobb and Farmer

21 © 2010 Bennett, McRobb and Farmer
Summary In this lecture you have learned about: The fundamental concepts of O-O Object, class, instance Generalization and specialization Message-passing and polymorphism Some of the advantages and justifications of O-O © 2010 Bennett, McRobb and Farmer

22 © 2010 Bennett, McRobb and Farmer
References Coad and Yourdon (1990) Booch (1994) OMG (2009) (For full bibliographic details, see Bennett, McRobb and Farmer) Lecturers may wish to add their own further reading here, or to give full details for these references. © 2010 Bennett, McRobb and Farmer


Download ppt "What Is Object-Orientation?"

Similar presentations


Ads by Google