Unit 4 : Object -Oriented Analysis - Principles O b j ec t i ves To introduce the basic principles of object -orientation : objects; classes of object; encapsulation; inheritance; and p o ly m o rp h i sm. WhatÕs object - orientation all about? Principles and techniques for system modelling which: Ð aim to produce a model of a system Ð provide notations and methods Advantages for software development: Ð reduces the Ôsemantic gapõ between reality and models Ð makes system understanding easier Ð allows local modification to models 4Ñ1
An Object An obje c t is: Ð " An abstraction of something in a problem domain, reflecting the capabilities of a system to keep information a b ou t it, in t e ra c t w i t h i t, o r b o t hó ( C o ad & Y ou r do n 1 9 91) Ð "An entity able to save a state (information) and which offers a number of operations (behaviour ) to either examine or affect this state " ( Jacobson 1992) Objects and Abstraction "An abstracti o n d e n ot e s t h e e s s e nt i a l c h ar a ct e r i s ti c s o f a n object that distinguish it from all other kinds of objects and thus provide crisply defied conceptual boundaries, relative to the perspective of the viewer " (Booch 1994) 4Ñ2
Sample of Objects from a ÒFood Manufacturing C o mpanyó Passive objects Ðone i n d iv i du a l s a c k o f l e n ti l s Ðone packet of herbal t ea Ðinvoice 63501 sent to A Farm, Lincolnshire Active objects Ðlorry "M235 BCM" Ðvan "N683 CNM" Ðfax machi n e i n R i ch a r d G r e en 's offi c e ÒFood Manufacturing CompanyÓ ( continued) Human agents ÐRichard Green ÐDavid Brown (Executive) ÐHill, D (Truck driver) Structure obj ec t s ÐMarketing Department 4Ñ3
and Associations Any obje c t h a s b o t h a t tr i b u te s a n d a s s oc i at i o ns A t t ri b u tes Ðcharacteristic features or properties Ðname / valu e pa i rs A s s oc i at i o n Ðany ki n d o f l i n k o r c o nn e c ti o n Ðbetween one obje c t a n d o n e o r a s e t of o t h er o b je c t s Characteristics private to an object are best represented as a t t ri b u tes Associations are hips Two essenti a l o p p os i t io n s : a g gr e g at i on vs r e f er e n ce r e l at i on s h i ps Ð aggregation relationships, where connection creates composite objects from simple objects Ð reference relationships where connection only refers to another object static vs dynamic relationships Ð static relationships, where coupling of objects is stored over a lo n g p e r io d o f t i m e, Ð dynamic relationships, which are established by operations 4Ñ4
Viewpoint of Association View and purpose affect definition of association Partition or division ÐAssociation indicating new objects created by s p l it t i n g o t h er ob j e c ts ap a r t, e.g. A b oo k Ôconsi s t s o f Õ or Ôcan be divided intoõ : title page, introduction, chapters, conclusion, i n de x Aggregation or amalgamation ÐAssociation indicating new objects created by adding other objects together e.g Covers, binding, end papers, printed p a ge s ar e Ôj o in e d i n Õ a book Structure and Behaviour of Object Gordon, Junior Librarian, as object M T W T F Name: Gordon Position: Junior Librarian Age: 25 Salary: 12,000... Loan out books Rename position Amend salary Supervisor Timetable Equipment 4Ñ5
Behaviour and Structure in a Food Manufacturing Company One packet of herbal tea Price: 2.95 Weight: 1kg... Order: 57891 Delivery: 57891A Supplier: A Farm Is Stored Is Sold Is Delivered Richard Green Age: 45 Sex: Male Managing Director Decide policies Attend meetings Manage Board meetings Lorry M235 BCN Reg: M235 BCN Weight: 7.5 tons Fuel level: 40 litres Driver Hill, D Trailer SSFG12 Deliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel... Marketing Department Staff: 50 people Location: High St Marketing Director Marketing Team Market All Products Choose New Products Determine Market Niches Object Identity Separate obj e ct s e ac h ha v e a un i qu e ob j e ct id e n ti t y Name: Gordon Position: Junior Librarian Age: 25 Salary: 12,000 Loan out books Rename position Amend salary... Name: Gordon Position: Junior Librarian Age: 25 Salary: 12,000... Loan out books Rename position Amend salary Supervisor Timetable Supervisor Equipment Timetable Equipment 4Ñ6
Dynamics of Objects Dynamics are generated through stimuli or messages passing between objects Receipt of a stimulus cause operation by (or in) the receiving o b j ec t Receipt of a stimulus can trigger sending of another stimulus to other objects 2 3 1 4 E n c a ps u l a tion ÒBehaviour and information are encapsulated in objectsó ( Jacobson 1992) ÒEncapsulation is the process of compartmentalising the elements of an abstraction that constitute its structure and behaviouró (Booch 1995) Only the 'interface' of an object is 'visible' to other objects Need, an d c an, on l y k n o w o p e ra t i on s o n a n o b j ec t, n o t h o w t h e y work nor about other characteristics Necessary prerequi s it e f o r i n fo r m at i on hi d i ng 4Ñ7
Encapsulation ( continued) Name Position Salary Age Loan out books Rename position Amend salary Encapsulation and abstraction are complementary concepts Abstraction focuses on the observable characteristics and behaviour of the object Encapsulation focuses on the representation derived from these characteristics Encapsulation requires : Ð explicit division between abstractions Ð clear separation of their concerns Classes of Object "abstracted from" Classes Classes represent groups of objects which have the same behaviour and information structures. Cl as s i s a k in d o f t y p e, an AD T ( bu t w i t h d a ta ), o r a n 'enti t y' (but with methods) Cl as s e s ar e th e s am e in b ot h a n al y s is a nd d e s ig n ÒA cl as s r ep r e s en t s a te m p l at e f o r s e v e ra l o b j ec t s... Ob j e ct s o f t h e s a m e c l as s h av e th e sa m e d e fi n it i o n b o t h f o r t h e ir operations and for their information structureó ( J ac o b so n 1 9 9 2) Common features 4Ñ8
Sample Classes from a ÒFood Manufacturing C o mpanyó Product Price Weight... Order Delivery Supplier Is Created Is Sold Is Delivered Employee Age Weight Sex Role Joins Company Leaves Company Reviewed Promoted Demoted Truck Department Registration No. Weight Fuel Driver Trailer Deliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel... Personnel Number Location... Director Marketing Team... Hire new staff Dismiss new staff Objects - Instances of Classes E v e ry ob j e ct is a n i n s ta n c e o f a s i n gl e cl a s s ÐA cl as s d e fi n e s t h e p o s s ib l e b e h av i ours an d t h e i n fo r m at i o n structure of all its object instances. Different instances may have their operations activated in different ways and in different sequences ; hence they may be in different states. Reg: M235 BCN Weight: 7.5 tons Fuel level: 40 litres Driver: Hill, D Trailer: SSFG12 Truck M235 BCN Deliveries Goods Repeat Until End Go To Destination Unload Goods EndRepeat Refuel... 4Ñ9
Instantiation of Objects Instantiation of a class generates an object, an instance of its c l ass Instantiation demands a specific create operation in every c l ass Truck Registration No. Weight Fuel Driver Trailor Create (Truck) Deliveries Goods Refuel Delete (Truck) I n h er itanc e Inheritence is a relationship between different classes which share common characteristics. Ò I f c l as s B i n h er i t s c l as s A, t he n bo t h t h e o p e ra t i on s an d information structure in class A will become part of class BÓ (Jacobsen 1992) Major benefits are simpler, clearer classes, at higher levels of a b s tr a c ti o n Employee Managing Director "is an" "inherits from" Truck Driver 4Ñ10
Generalisation & Specialisation G e n er a l is a t io n ÐCreation of an 'ancestor' Speci a li s at i o n ÐCreation of a 'descendant' Managing Director Warehouse Admin Employee "is an" "inherits from" Clerical Worker "is a" "inherits from" Office Admin Truck Driver Multiple Inheritance 1 class inherits from 2 or more existing classes ÐAllows more complex class structures, but less easily u n de r s t oo d librarian long-term staff short-term staff counter staff repair staff circulation staff other staff 4Ñ11
Ambiguities through Multiple Inheritance Name Clashes Incorrect repeated inheritance : A (..A..) (..A..) (..A..)?? Pol y morphis m System behavi o ur is d ef i ne d b y th e d y na m i c b e h av i ou r o f instances of classes ÒPolymorphism means that the sender of a stimulus does not need to know the receiving instance's class. The receiving instance can belong to an arbitary classó (Jacobsen 1992) Polymorphism enables different instances of different classes to be associated A receiv i n g i n s ta n ce i nt e r pr e t s s t i m ul i a c c or d in g t o i t s o w n c l ass 4Ñ12
Key Points Basic Concepts Ð object : entity combining essential characteristics abstracted from a system domain Ð class : expression of common characteristics of objects Ð encapsulation : combination of attributes and operations in a single self- contained object Ð inheritance : relationship between superclass and subclass defining levels of commonality Ð polymorphism : facility allowing stimuli to ignore class of receiving o b je c t Application of concepts enables: object identification, object modelling and behaviour modelling 4Ñ13