Presentation is loading. Please wait.

Presentation is loading. Please wait.

Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts.

Similar presentations


Presentation on theme: "Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts."— Presentation transcript:

1 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts

2 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 2 OOP basic concepts With abstraction, we identify essential features of a system Encapsulation is the packing of information with objects Objects are entities containing data and procedures The methods describe the dynamic behaviour of objects, representing the service they provide Message: a request to execute a method A class is a template for creating objects An instance is an object that belongs to a class With inheritance, we can reuse class specifications A class hierarchy is tree structure showing inheritance relations With polymorphism, we can hide different implementations of a method Independence: an object should be responsible for itself Interfaces describe how users interact with a class

3 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 3 Abstraction Ability to view ”real world” problems with varying degrees of detail

4 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 4 Encapsulation The packaging of several items into one single unit + =

5 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 5 Encapsulation Objects carry with themselves everything they need to perform their function (data and methods in the same entity) Makes it possible to hide information from the outside world

6 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 6 What is an object? Our commonsense concept of an entity with meaning. For example: –Physical entity: a car –Abstract entity: an angel –Conceptual entity: blueprint for an airplane –Software entity: an array

7 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 7 Common properties in objects Boundaries: the object is well defined State: how is it now Behaviour: the object can change state Identity: it has a name

8 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 8 Objects and classes We group objects into classes For example, the classes of airplanes, dogs, people, cars, busses … The objects of a class have common: –properties: all planes have wings, windows, shape… –behaviour: airplanes can fly, turn, land,… –semantics: press the right button to takeoff The buss (object) you took yesterday is an instance of the class of busses

9 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 9 Class: example The class of all courses offered by IDE Attritubes or properties (what kind of information has the object?): name, code, period, shedule,… Operations or behaviour (what can we do with a course?): (un)register a student, assign a lecturer, check if it is full,… What is the semantics?

10 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 10 Sections of a class A class has 3 sections: Course Name Code … Register() Is_full() Lecturer() … First section: the class name Second session: the class attributes Third section: the behaviour of the class (operations or metods)

11 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 11 Relationships between objects Association (aggregation and composition) Dependency Generalization (inheritance)

12 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 12 Association Connection among classes with structural dependence Course Name Code … … University Name Code … … Is given by Association Association name

13 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 13 Association and multiplicity Course Name Code … … University Name Code … … 5..10 is 1 given by multiplicity Student Name Code … … 1 is 1..5 reading

14 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 14 Association and multiplicity Unspecified Exactly one 2..4 0..1 1..* 0..* 1 * 2, 4..6 One or more Zero or one Specified range Multiple, disjoint ranges Zero or more (unlimited) }

15 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 15 Association types Aggregation Composition

16 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 16 Dependency relation Connection among classes without structural dependence A client depends on the delevery boy to receive the pizza: but the delivery boy can be changed, and this should not make any difference for the client.

17 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 17 Generalization Hierarchy of abstractions (single and multiple inheritance) ”is-a” relationship A penguin is a bird

18 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 18 Single inheritance Inheritance from one class Superclass Subclasses Generalization relationship

19 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 19 Multiple inheritance Inheritance from more than one class Superclasses Subclass Generalization relationship

20 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 20 What is inherited? A subclass inherits the attibutes, methods and relationships from the superclass And can also –Add additional attibutes, operations, relationships –Redefine inherited methods

21 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 21 Cohesion Tightly coupled systems –Missuse or orveruse of composition –Difficult to change

22 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 22 Cohesion Loosely coupled systems –Missuse or orveruse of inheritance –Difficult to use

23 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 23 Problem You are requested to build a system to help bird researchers to keep track of their birds and observations. What is the most general class?

24 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 24 Inheritance Factor out commonality go to from the general to the specific

25 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 25 Inheritance Generalization-specialization concept: penguins don’t fly! Possible solution: specilize the class into two

26 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 26 Inheritance and encapsulation Inheritance can weaken encapsulation: if you change the superclass, the change is reflected in the hierarchy. What’s the problem here?

27 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 27 Inheritance and encapsulation Subtleties in the ”is-a” relationship: a window in a GUI is much more than a rectangle

28 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 28 Polymorphism Different behaviour for the same message Overloading

29 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 29 Composition Objects can include other objects: a car has an engine, and the engine is itself a separate entity or object

30 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 30 Aggregation and association Aggregation: a car has an engine Association: a computer has a keyboard Can you explain the difference in the relationships in the following diagram?

31 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 31 Dependencies How can we avoid making objects highly dependent when using composition? Mixing domains increase dependency, but can be useful: for example, VCR and DVD player in the same unit

32 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 32 Cardinality of composition The number of objetcs that participate in a composition: –Which objects collaborate with which objects? –How many objects participate in each collaboration? –Is the collaboration optional or mandatory?

33 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 33 More relationships Constructed-with: a stack is constructed with a list Knows-of: a browser knows of which platform it is executing

34 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 34 Cardinality of composition Example: the department offers several courses. Each course must have at least 1 lecturer, and a lecturer can have zero or more children. A course have at most 30 students and at least 10. Draw a class hierarchy for this example How can you represent the cardinality in an implementation language?

35 Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 35 Someone was developing an email system and came up with the diagram bellow. Explain its meaning based on your knowledge:


Download ppt "Marcelo Santos – OOAD-CDT309, Spring 2008, IDE-MdH 1 Object-Oriented Analysis and Design - CDT309 Period 4, Spring 2008 Object-oriented concepts."

Similar presentations


Ads by Google