Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts.

Similar presentations


Presentation on theme: "1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts."— Presentation transcript:

1 1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts

2 2 Objects and Classes – the basic concepts Use cases model the user’s view of the functionality of a system. Each use case represents a task or major chunk of functionality Object orientated software structure based on objects Objects must deliver all the system functionality

3 3 What is an object? The most important concept in object- orientated development A representation of something in the application domain about which we need to store data to enable the system to provide the required functionality.

4 4 What is an object? aBike :Bike type = men’s dailyHireRate = £8 deposit = £50 Object name – two optional parts, both underlined aBike = this specific object’s name Bike = the class the object belongs to The object’s attribute values Attributes are data items defined as part of an object or class. type is an attribute men’s is the value of the ‘type’ attribute for this object 2 sections, top is the object’s name, bottom is the object’s attribute values

5 5 More about objects Every object belongs to a class Objects in an O-O system can represent –physical things (customers, products, members, and books), –conceptual things (orders, loans, reservations and cancellations) –organizational things (companies or departments). –computer implementation features (GUI windows, files or linked lists)

6 6 More about objects Every object in a system has three characteristics – Behaviour, real world objects have certain attributes and behaviour – State, object behaviour may vary depending on its state – Identity, each object has a unique identity and existence

7 7 Object characteristics – behaviour Real world objects Car has data and characteristic behaviour. Data – amount of fuel, engine temperature, speed. Behaviour – stop, start, move. Object orientated objects In OO data becomes attributes Behaviour becomes operations (procedures) Data and behaviour are packaged together

8 8 Object characteristics – state An object’s state is determined by the value of its attributes e.g. Bank a/c with no overdraft allowed Attribute determining state = balance Value of balance attribute = £100 Behaviour – Withdrawal of £90 allowed Withdrawal of £150 denied Value of balance attribute = £300 Behaviour –

9 9 Object characteristics – identity Every object has an identity Every object is a unique Each object has a separate existence and ultimately a separate space in memory Objects whose attribute values are identical are totally distinct from one another.

10 Identification Of Objects  Many methodologists have their own favorite approaches  All techniques have short comings  fail to identify all objects  identifies false objects

11 Using The Things To Be Modeled Basic Steps Are: –Identify individual or group things, such as persons, roles, organizations, logs, reports, forms, etc. in the application domain –Identify the corresponding objects and classes Requires significant experience with OO to apply successfully

12 Using Nouns This assumes that written documents about the domain exist Steps are: –Obtain or author a narrative English text that represents an informal description of the problem to be solved. –Use the nouns, pronouns, and noun phrases to identify objects and classes –Verbs and predicate phrases are used to identify services

13 13 Encapsulation - packaging related data and operations together Data hiding – making the internal details of an object inaccessible to another object Public interface – provides the services an object makes available to other objects. Encapsulation

14 14 Encapsulation data Operations Data inside an object is surrounded by a protective ring of operations The data is protected by the operations that encapsulate it. Public interface – an object’s name, class and operations, the only parts of the object accessible to other objects.

15 15 Class An object is defined in terms of its class A class of objects is a group of objects with the same set of attributes, relationships and behaviour An object is an instance of a class Instantiation is creating a new object

16 16 Class Bike bike# available type size make model dailyHireRate deposit getCharges (no.days) findBike (bike#) registerBike (bikeDetails) getBike# () Class name – starts with capital letter, if two words ‘CarPark’ Attributes – lower case, no spaces, each subsequent word starts with capital letter Operations – same notation as attributes

17 17 Relationships Three types of relationships Association Aggregation Generalization (Inheritance) Dependency These are links between classes that are used for message passing A navigable path between objects

18 18 Association – a link between two classes indicating a relationship 0..* Student 1..* Course 0..*1..* studies Association relationship between Student and Course classes The association can be named: a student studies a course. An association has two ends each attached to a class. The numbers and asterisk on the line indicate the multiplicity of the association.

19 19 Multiplicity – UML notation MeaningExampleNotation an exact number exactly one exactly six 1 (or may be omitted) 6 manyzero or more one or more 0..* 1..* a specific range one to four, zero to six 1..4, 0..6, a choicetwo or four or five2, 4, 5 unspecifiedan arbitrary, unspecified number *

20 20 Aggregation – a whole-part relationship Identified by - 'consists of', 'has a', or 'is a part of‘ Wheels, doors and engine are ‘part’ of a car

21 21 Composition – tighter aggregation the whole object has exclusive ownership of its parts i.e. the part object can only participate in one aggregation; the parts live and die with the whole

22 22 Inheritance and generalization Inheritance – mechanism for defining a new class in terms of an existing class Generalization – moving common attributes and operations in to a more general class VisitorsCard cardNumber currentDate delete () StaffCard cardNumber name dept expiryDate delete ()

23 23 Inheritance and generalization a specialized class inherits from a general class a subclass inherits from a superclass a child class inherits from a parent class a derived class inherits from a base class. Relationship described as ‘is-a’ ‘is–a-type-of’ ‘is–a–kind–of’

24 24 Abstract class – never instantiated Card {abstract} cardNumber delete() Inheritance a relationship between classes Card objects will never be created (instantiated)

25 25 Polymorphism The term polymorphism means the ability for a single message to produce a different response depending on the class of the object to which it is sent. Polymorphism linked with an inheritance hierarchy allows a single message to be interpreted differently by different objects. Which method is executed will depend on which object receives the message. A single operation may be implemented by more than one method.

26 26


Download ppt "1 A Student Guide to Object- Orientated Systems Chapter 4 Objects and Classes: the basic concepts."

Similar presentations


Ads by Google