unit 1( modelling concepts & class modeling)

122

Upload: manoj-reddy

Post on 01-Jul-2015

303 views

Category:

Engineering


2 download

DESCRIPTION

Unit 1( modelling concepts & class modeling)

TRANSCRIPT

Page 1: Unit  1( modelling concepts & class modeling)
Page 2: Unit  1( modelling concepts & class modeling)

https://sites.google.com/a/cmrit.ac.in/manoj-c5559/

Page 3: Unit  1( modelling concepts & class modeling)

PrerequisiteThe course is aimed at:

Students who have prior knowledge to the concept of Software Engineering.

Object oriented language like C++.

Page 4: Unit  1( modelling concepts & class modeling)

Polymorphism - Ability of different objects to response same message in different ways.

Circle

Rectangle

Triangle

Draw

Page 5: Unit  1( modelling concepts & class modeling)

Inheritance

Page 6: Unit  1( modelling concepts & class modeling)

InheritanceOne class can be used to derive another via inheritance

Classes can be organized into hierarchies

6

Bank Account

Account

Charge Account

Savings Account

Checking Account

Page 7: Unit  1( modelling concepts & class modeling)

Abstraction

Page 8: Unit  1( modelling concepts & class modeling)

8

Encapsulation

Page 9: Unit  1( modelling concepts & class modeling)

Learning Outcomes:At the end of the course the student would have the:

The Knowledge of the basic concepts of Object oriented modeling and Design.

Will be able to use the Object Oriented notations and process that extends from analysis through design to implementations.

Be able to use all the standard UML notations.

Capable to model the requirements with use cases and describe the dynamic behavior and structure of the design. Easily create a modular design with components and relate the logical design to the physical environment.

The Student will be able to use the concept of design patterns and apply it where suitable.

Page 10: Unit  1( modelling concepts & class modeling)
Page 11: Unit  1( modelling concepts & class modeling)

UML: Unified Modeling Language An industry-standard graphical language for specifying,

visualizing, constructing and documenting the software systems, as well as for business modeling.

The UML uses mostly graphical notations to express the OO modeling and design of software projects.

Simplifies the complex process of software design

What is UML?

Page 12: Unit  1( modelling concepts & class modeling)

Why we use UML?

Use graphical notation: more clearly than natural language and code.

Help acquire an overall view of a system.

UML is not dependent on any one language or technology.

Page 13: Unit  1( modelling concepts & class modeling)

How to use UML diagrams to design software system?

Types of UML Diagrams:

Use Case Diagram Class Diagram Sequence Diagram Collaboration Diagram State Diagram

Page 14: Unit  1( modelling concepts & class modeling)

Different Views

14

Users Designers Analyzers

Page 15: Unit  1( modelling concepts & class modeling)

UML Diagram – The Unified Modeling Language (UML) is a standard language for

15

Specifying Visualizing Constructing Documenting

Business Modeling Communications

Page 16: Unit  1( modelling concepts & class modeling)

UNIT – 1 : Introduction-Modeling Concepts, class Modeling

What is Object Orientation? What is OO development? OO themes; Evidence for usefulness of OO development; OO modeling history

Modeling as Design Technique: Modeling; abstraction; The three models.

Class Modeling: Object and class concepts; Link and associations concepts; Generalization and inheritance; A sample class model; Navigation of class models; Practical tips.

Page 17: Unit  1( modelling concepts & class modeling)

Object-Oriented Modelling and Design

Object-Oriented Modelling and Design is a way of thinking about problems using models organized around real world concepts. The fundamental construct is the object, which combines both data and behaviour.

Page 18: Unit  1( modelling concepts & class modeling)

ObjectsAn object has:

state - descriptive characteristics

behaviors - what it can do (or what can be done to it)

The state of a bank account includes its account number and its current balance

The behaviors associated with a bank account include the ability to make deposits and withdrawals

Note that the behavior of an object might change its state

18

Page 19: Unit  1( modelling concepts & class modeling)

19

• Objects have three responsibilities:

What they know about themselves – (e.g., Attributes)

What they do – (e.g., Operations)

What they know about other objects – (e.g., Relationships)

Objects

Page 20: Unit  1( modelling concepts & class modeling)

20

Page 21: Unit  1( modelling concepts & class modeling)

ObjectsSoftware objects model read-world objects or abstract concepts

• dog, bicycle, Bank accountReal-world objects have states and behaviors

• Dogs' states: name, color, breed, hungry• Dogs' behaviors: barking fetching• Bicycle ‘s State :• Bicycle’ s behavior :

Other examples of objects are: myself – an instructor object. you – a student objectthis room – a room objectthis universityyour car, etc.

Page 22: Unit  1( modelling concepts & class modeling)

What is Object-Orientation about?

One of the key challenges faced by Computer Scientist is how to handle complexity.

Two main concepts used to manage complexity are Modularity and Abstractions.Modularity means breaking a large system up into smaller pieces until each

peace becomes simple enough to be handled easily.

Abstraction focus on essential aspects of an application while ignoring details.

Over the years, computer scientists have developed a number of approaches to achieve modularity and abstraction.

The latest of these approaches is Object-Orientation or OO for short.

The key concept in OO is of course Object,

Page 23: Unit  1( modelling concepts & class modeling)

Object-Oriented

Software is organized as a collection of discrete objects that incorporate both State and behavior.

Four aspects (characteristics) required by an OO approach are -

Identity

Classification

Polymorphism

Inheritance

23

Page 24: Unit  1( modelling concepts & class modeling)

Identity

Identity means that data is organized into discrete, distinguishable entities called objects.

E.g. for objects: personal computer, bicycle

Objects can be concrete (such as a file in a file system) or conceptual (such as scheduling policy in a multiprocessing OS). Each object has its own inherent identity. (i.e two objects are distinct even if all their attribute values are identical).

24

Page 25: Unit  1( modelling concepts & class modeling)

25

Page 26: Unit  1( modelling concepts & class modeling)

ClassificationIt means that objects with same data structure (attribute) and

behavior (operations) are grouped into a class.

Each object is said to be an instance of its class.

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.

A class is the blueprint from which the individual objects are created.

26

Page 27: Unit  1( modelling concepts & class modeling)

Classes – ExampleClasses – Example

27

AccountAccountAccountAccount

+Owner: Person+Owner: Person+Amount: double+Amount: double+Owner: Person+Owner: Person+Amount: double+Amount: double

+suspend()+suspend()+deposit(sum:double)+deposit(sum:double)+withdraw(sum:double)+withdraw(sum:double)

+suspend()+suspend()+deposit(sum:double)+deposit(sum:double)+withdraw(sum:double)+withdraw(sum:double)

ClassClassClassClassAttributesAttributesAttributesAttributes

OperationsOperationsOperationsOperations

Page 28: Unit  1( modelling concepts & class modeling)

Classes and Objects – ExampleClasses and Objects – Example

28

AccountAccountAccountAccount

+Owner: Person+Owner: Person+Amount: double+Amount: double+Owner: Person+Owner: Person+Amount: double+Amount: double

+suspend()+suspend()+deposit(sum:double)+deposit(sum:double)+withdraw(sum:double)+withdraw(sum:double)

+suspend()+suspend()+deposit(sum:double)+deposit(sum:double)+withdraw(sum:double)+withdraw(sum:double)

ClassClassClassClass ivanAccountivanAccountivanAccountivanAccount

+Owner=“ABC"+Owner=“ABC"+Amount=5000.0+Amount=5000.0+Owner=“ABC"+Owner=“ABC"+Amount=5000.0+Amount=5000.0

peterAccountpeterAccountpeterAccountpeterAccount

+Owner=“XYZ"+Owner=“XYZ"+Amount=1825.33+Amount=1825.33+Owner=“XYZ"+Owner=“XYZ"+Amount=1825.33+Amount=1825.33

kirilAccountkirilAccountkirilAccountkirilAccount

+Owner=“CSE”+Owner=“CSE”+Amount=25.0+Amount=25.0+Owner=“CSE”+Owner=“CSE”+Amount=25.0+Amount=25.0

ObjectObjectObjectObject

ObjectObjectObjectObject

ObjectObjectObjectObject

Page 29: Unit  1( modelling concepts & class modeling)
Page 30: Unit  1( modelling concepts & class modeling)

Polymorphism

It means that the same operation (i.e. action or transformation that the object performs) may behave differently on different classes.

Ability of different objects to response same message in different ways.

30

Page 31: Unit  1( modelling concepts & class modeling)

Polymorphism

Circle

Rectangle

Triangle

Draw

Page 32: Unit  1( modelling concepts & class modeling)

Inheritance

It is the sharing of attributes and operations among classes based on a hierarchical relationship.

Subclasses can be formed from broadly defined class.Each subclass incorporates or inherits all the

properties of its super class and adds its own unique properties.

32

Page 33: Unit  1( modelling concepts & class modeling)

Inheritance

Page 34: Unit  1( modelling concepts & class modeling)

Object-Oriented Development

Development refers to Software Life Cycle.

OOD approach encourages software developers to work and think in terms of the application domain through most of the software engineering life cycle.

34

Page 35: Unit  1( modelling concepts & class modeling)
Page 36: Unit  1( modelling concepts & class modeling)
Page 37: Unit  1( modelling concepts & class modeling)

Software Life Cycle

Software life cycle (or software process) - series of identifiable stages that a software product undergoes during its life time.

Feasibility study Requirements analysis and specification Design Coding Testing Maintenance

Page 38: Unit  1( modelling concepts & class modeling)

Object-Oriented Methodology The process for OO development and graphical notation for

representing OO concepts consists of building a model of an application and then adding details to it during design.

The methodology has the following stages: System conception : Software development begins with business

analysis or users conceiving an application and formulating tentative requirements

Analysis : The analyst must work with the requestor to understand the problem, because problem statements are rarely complete or correct.

The analysis model is a precise abstraction of what the desired system must do, not how it will be done.

It should not contain implementation decisions.

38

Page 39: Unit  1( modelling concepts & class modeling)

Object-oriented methodologyThe analysis model has 2 parts:

Domain model - a description of the real-world objects reflected within the system

Eg: Domain objects for a stock broker

Application – model - a description of the parts of the application system itself that are visible to the user.

Eg:- Application might include stock, bond, trade and commission.

Application objects might control the execution of trades and present the results.

Page 40: Unit  1( modelling concepts & class modeling)

Object-oriented methodology System design: The development teams devise a high – level

strategy – the system architecture for solving the application problem.

They also establish policies that will serve as a default for the subsequent, more detailed portions of design.

The system designer must decide what performance characteristics to optimize, choose a strategy of attacking the problem and make tentative resource allocations.

Class design : The class designer adds details to the analysis model in accordance with the system design strategy.

The focus of class design is the data structures and algorithms needed to implement each class.

Page 41: Unit  1( modelling concepts & class modeling)

Object-oriented methodology

Implementation : Implementers translate the classes and relationships developed during class design into particular programming language, database or hardware.

During implementation, it is important to follow good software engineering practice so that traceability to the design is apparent and so that the system remains flexible and extensible.

Page 42: Unit  1( modelling concepts & class modeling)

Object oriented ThemesAbstraction: let’s focus on essential aspects of an application while

ignoring details.

Encapsulation :( Information Hiding) separates the external aspects of an object , that are accessible to other objects from internal implementation details.

Sharing (reuse)

Emphasis on the essence of an object: OO technology stresses what an object is, rather than how it is used.

Synergy: Identity, classification, polymorphism, and inheritance characterize OO languages. Use all together.

Page 43: Unit  1( modelling concepts & class modeling)

43

Page 44: Unit  1( modelling concepts & class modeling)

44

Page 45: Unit  1( modelling concepts & class modeling)

Evidence for usefulness of OOD

Evidence for usefulness of OO development

Applications at General Electric Research and Development Center.(1990)OO techniques for developing compilers, graphics, user interfaces,

databases ,an OO language, etc.OO technology is a part of the computer science and software engineering

mainstream. Important forums: (OOPSLA,ECOOP) Object Oriented Programming

systems, Languages and applications. European Conference on OOP.

Page 46: Unit  1( modelling concepts & class modeling)

OO Modeling history

Work at GE R&D led to OMT(Object-Modeling Technique) in 1991.

Rumbaugh, Grady Booch on unifying the OMT and Booch Notaions in 1994.

In 1996 the OMG(Object Management Group) issued a request for the proposals for a standard OO modeling notation.

1997 UML was accepted by OMG as a standard.In 2001 OMG released UML Added features and released UML in 2004.

www.omg.org

Page 47: Unit  1( modelling concepts & class modeling)

2000: UML 1.3

1998: UML 1.2

1997: UML 1.0, 1.1

1996: UML 0.9 & 0.91

1995: Unified Method 0.8

Year & Version of UML 2011:UML 2.4

2010:UML2.3

2009:UML2.2

2007: UML 2.1.1

2005: UML 2.0

2003: UML 1.5

2001: UML 1.4

Page 48: Unit  1( modelling concepts & class modeling)
Page 49: Unit  1( modelling concepts & class modeling)

What is Modeling

Modeling consists of building an abstraction of reality.

Abstractions are simplifications because:They ignore irrelevant details andThey only represent the relevant details.

What is relevant or irrelevant depends on the purpose of the model.

Page 50: Unit  1( modelling concepts & class modeling)

50

What is a Model

A model is a simplification of reality.

A model may provideblueprints of a systemOrganization of the systemDynamic of the system

Page 51: Unit  1( modelling concepts & class modeling)

MODEL A model is an abstraction, before building any system a

prototype may be developed. The main purpose of model is for understanding of the system.

Designer build different kinds of models for various purposes before constructing things.

For example car , airplane, blueprints of machine parts, Plan for house construction etc., Models serve many purposes

Page 52: Unit  1( modelling concepts & class modeling)
Page 53: Unit  1( modelling concepts & class modeling)
Page 54: Unit  1( modelling concepts & class modeling)
Page 55: Unit  1( modelling concepts & class modeling)

55

Importance of Modeling

Models help usto visualize a system as it is or as we want it to be.to specify the structure or behavior of a system.in providing a template that guides us in constructing a

system.in providing documenting the decisions we have made.

Page 56: Unit  1( modelling concepts & class modeling)

Purpose of Modeling

Designers build many kinds of models for various purposes before constructing things.

Models serve several purposes –

Testing a physical entity before building (simulation)

Communication with customer

Visualization

Reduction of complexity

Better understanding of the problem

Page 57: Unit  1( modelling concepts & class modeling)

Purpose of Modeling

Communication with customers

Architects and product designers build models to show their customers. Mock ups are demonstration products that imitate some or all of the external behaviour of a system.

Page 58: Unit  1( modelling concepts & class modeling)

Purpose of Modeling

Visualization Storyboards of movies, television shows and

advertisements let writers see how their ideas flow. They can modify awkward transitions, and unnecessary segments before detailed writing begins.

Page 59: Unit  1( modelling concepts & class modeling)

Purpose of Modeling

Reduction of complexity The main reason for modeling is to deal with systems that

are too complex to understand directly. Models reduce complexity by separating out a small number of important things to deal with at a time.

Page 60: Unit  1( modelling concepts & class modeling)

Three models

We use three kinds of models to describe a system from different view points.

1.Class Model for the objects in the system & their relationships.

2. State model—for the life history of objects. Show how systems behave internally

3. Interaction Model—for the interaction among objects. Show the behaviour of systems in terms of how objects interact

with each other

Page 61: Unit  1( modelling concepts & class modeling)
Page 62: Unit  1( modelling concepts & class modeling)

Class diagrams

Class diagrams provide a graphic notation for modeling classes and their relationships, thereby describing possible objects

Note: An object diagram shows individual objects and their relationships.

Page 63: Unit  1( modelling concepts & class modeling)

Class diagrams

ClassName

attributes

operations

A class is a description of a set of objects that share the same attributes,operations, relationships, and semantics.

Graphically, a class is rendered as a rectangle, usually including its name,attributes, and operations in separate,designated compartments.

Page 64: Unit  1( modelling concepts & class modeling)

Class Names

ClassName

attributes

operations

The name of the class is the only required tag in the graphical representation of a class. It always appears in the top-most compartment.

Page 65: Unit  1( modelling concepts & class modeling)

Class Attributes

Person

name : Stringaddress : Addressbirthdate : Datessn : Id

An attribute is a named property of a class that describes the object being modeled.In the class diagram, attributes appear in the second compartment just below the name-compartment.

Page 66: Unit  1( modelling concepts & class modeling)

Class Operations

Person

name : Stringaddress : Addressbirthdate : Datessn : Id

eatsleepworkplay

Operations describe the class behavior and appear in the third compartment.

Page 67: Unit  1( modelling concepts & class modeling)

An example of Class

Account_Name- Custom_Name- Balance

+AddFunds( )+WithDraw( )+Transfer( )

Name

Attributes

Operations

Page 68: Unit  1( modelling concepts & class modeling)

Conventions used (UML) in Class Diagrams

Page 69: Unit  1( modelling concepts & class modeling)

Conventions used (UML):• UML symbol for both classes and objects is box.

• Objects are modeled using box with object name followed by colon followed by class name, Both the names are underlined.

• Use boldface to list class name, center the name in the box and capitalize the first letter. Use singular nouns for names of classes.

• To run together multiword names (such as JoeSmith), separate the words With intervening capital letter.

Page 70: Unit  1( modelling concepts & class modeling)

Values and Attributes:

Value is a piece of data.Attribute is a named property of a class that describes a

value held by each object of the class.

E.g. Attributes: Name, bdate, weight.

Values: JoeSmith, 21 October 1983, 64.

Page 71: Unit  1( modelling concepts & class modeling)

Conventions used (UML):

List attributes in the 2nd compartment of the class box.

A colon precedes the type, an equal sign precedes default value.

Show attribute name in regular face, left align the name in the box and use small case for the first letter.

Similarly we may also include attribute values in the 2nd compartment of object boxes with same conventions.

Page 72: Unit  1( modelling concepts & class modeling)

Do not list object identifiers

Page 73: Unit  1( modelling concepts & class modeling)

Operations and Methods:

An operation is a function or procedure that maybe applied to or by objects in a class.

E.g. Hire, fire and pay dividend are operations on Class Company. Open, close, hide and redisplay are operations on class window.

A method is the implementation of an operation for a class.E.g. In class file, print is an operation you could implement

different methods to print files.

Note: Same operation may apply to many different classes. Such an operation is polymorphic.

Page 74: Unit  1( modelling concepts & class modeling)

UML conventions used –List operations in 3rd compartment of class box.List operation name in regular face, left align and use lower case for first letter.Optional details like argument list and return type may follow each operation name. Parenthesis enclose an argument list, commas separate the arguments. A colon precedes the result type.Note: We do not list operations for objects, because they do not vary amongobjects of same class.

Page 75: Unit  1( modelling concepts & class modeling)
Page 76: Unit  1( modelling concepts & class modeling)

76

Links and Association Links and associations are the means for establishing

relationships among objects and classes.

A link is a physical or conceptual connection among objects.

E.g. JoeSmith WorksFor Simplex Company.

An association is a description of a group of links with common structure and common semantics.

E.g. a person WorksFor a company.

Page 77: Unit  1( modelling concepts & class modeling)

Conventions used (UML):

Link is a line between objects

Association connects related classes and is also denoted by a line.

Show link and association names in italics.

Page 78: Unit  1( modelling concepts & class modeling)

Association

Associations are inherently bi-directional.

The association name is usually read in a particular direction but the binary association may be traversed in either direction.

Page 79: Unit  1( modelling concepts & class modeling)

79

UML Association Notation

In the UML, a navigable association is represented by an open arrow.

BankAccount Person

Page 80: Unit  1( modelling concepts & class modeling)

80

UML Binary Association Notation

A binary association is drawn as a solid path connecting two classes or both ends may be connected to the same class.

Company Person

Person• Self Associated involving class Person

Page 81: Unit  1( modelling concepts & class modeling)

Associations: MultiplicityMultiplicity defines the number of

objects associated with an instance of the association.

UML diagrams explicitly list multiplicity at the end of association lines.

Intervals are used to express multiplicity:

Car Person

transports

passenger

Car Person

transports

passenger

5

Car Person

transports

passenger

*

Car Person

transports

passenger

1..*

Car Person

transports

passenger

2..5

Page 82: Unit  1( modelling concepts & class modeling)

82

Associations and Multiplicity An association is used to show how two classes are related to each other

Symbols indicating multiplicity are shown at each end of the association

Page 83: Unit  1( modelling concepts & class modeling)

Many-to-one– Bank has many ATMs, ATM knows only 1 bank

One-to-many– Inventory has many items, items know 1 inventory

Page 84: Unit  1( modelling concepts & class modeling)
Page 85: Unit  1( modelling concepts & class modeling)

© 85

Analyzing and validating associations

Many-to-one A company has many employees, An employee can only work for one company. A company can have zero employees

E.g. a ‘shell’ company It is not possible to be an employee unless you work for a company

* worksForEmployee Company1

Page 86: Unit  1( modelling concepts & class modeling)

© 86

Analyzing and validating associations

Many-to-many A secretary can work for many managers A manager can have many secretaries Managers can have a group of secretaries Some managers might have zero secretaries.

*

supervisor

*****1..*Secretary Manager

Page 87: Unit  1( modelling concepts & class modeling)

© 87

Analyzing and validating associations

One-to-one For each company, there is exactly one board of directors A board is the board of only one company A company must always have a board A board must always be of some company

Company BoardOfDirectors11

Page 88: Unit  1( modelling concepts & class modeling)

Association RelationshipsIf two classes in a model need to communicate with each other, there must be link between them.

An association denotes that link.

InstructorStudent

Page 89: Unit  1( modelling concepts & class modeling)

Association Relationships (Cont’d)

We can indicate the multiplicity of an association by adding multiplicity relationships to the line denoting the association.

The example indicates that a Student has one or more Instructors:

InstructorStudent1..*

Page 90: Unit  1( modelling concepts & class modeling)

Association Relationships (Cont’d)

The example indicates that every Instructor has one or more Students:

InstructorStudent1..*

Page 91: Unit  1( modelling concepts & class modeling)

Association Relationships (Cont’d)We can also indicate the behavior of an object in an association (i.e., the role of an object) using rolenames.

InstructorStudent1..*1..*

learns fromteaches

Page 92: Unit  1( modelling concepts & class modeling)

one-to-one multiplicity

Page 93: Unit  1( modelling concepts & class modeling)

Coming up: Questions

Multiplicity ConstraintsStudent

Class Section

Course

Semester

Instructor

Department

takes>

is registered for>

teaches>

sponsors>

<w

orks

for is instance of>

is he

ld d

urin

g>

1..*1

1..*

1..*11

1..*

0..8

0..*

0..61..3

Page 94: Unit  1( modelling concepts & class modeling)

Association Ends

Associations have ends. They are called ‘Association Ends’.They may have names (which often appear in problem

descriptions).

Page 95: Unit  1( modelling concepts & class modeling)

Association EndsUse of association end names is optional.But association end names are useful for traversing associations.Association end names are necessary for associations between

objects of the same class.When constructing class diagrams you should properly use

association end names and not introduce a separate class for each reference. Two instances represent a person with a child one for child and one for parent.

In the correct model, one person instance participates in2 or more links, twice as a parent and zero or more times as a child.

Page 96: Unit  1( modelling concepts & class modeling)

Example of association ends use

Page 97: Unit  1( modelling concepts & class modeling)

Association: ordering, bag, sequence On a ‘many” association end, sometimes, it is required that objects

have an explicit order. In this case the ordering is an inherent part of the association

A workstation screen contains a number of overlapping windows. Each window on a screen occurs at most once. The windows have an explicit order so only the topmost window is visible.

The ordering is an inherent part of the association. If objects indicate ordered set objects by

writing ―{ordered} next to appropriate association end. ‖Example:

Page 98: Unit  1( modelling concepts & class modeling)

Association: ordering, bag, sequenceA bag is a collection of elements with duplicates allowed.A sequence is an ordered collection of elements with duplicates allowedBag: collection of elements with duplicates allowed. • Sequence: ordered collection of elements with duplicate allowed eg. An

itinerary is a sequence of airports and the same airport can be visited more than once.

• Sequence is ordered bag allow duplicates, {ordered} and {sequence}only difference is sequence allows duplicates as shown in figure 14.

Page 99: Unit  1( modelling concepts & class modeling)

Association class UML offers the ability to describe links of association with

attributes like any class.An association class is an association that is also a class.

Page 100: Unit  1( modelling concepts & class modeling)

Association classExamples:

Page 101: Unit  1( modelling concepts & class modeling)

Association classExample

Page 102: Unit  1( modelling concepts & class modeling)

Qualified Association

A qualified association is an association in which an attribute called Qualifier the objects for a ‘many’ association’ end.

A qualifier selects among the target objects, reducing the effective multiplicity from ‘many’ to ‘one’.

Both below models are acceptable but the qualified model adds information.

Page 103: Unit  1( modelling concepts & class modeling)

Qualified Association

Example:

Page 104: Unit  1( modelling concepts & class modeling)

Figure 5-9. Example of how a qualified association reduces multiplicity (UML class diagram). Adding a qualifier clarifies the class diagram and increases the conveyed information. In this case, the model including the qualification denotes that the name of a file is unique within a directory.

Directory Filefilename

Directory

File

filename

1

W ithout qualification

W ith qualification

*

0..11

Page 105: Unit  1( modelling concepts & class modeling)

105

GeneralizationDeriving a class out of a parent class having some inherited property(from

the parent class) and some new property of the derived class.The term generalization is for the inheritance in the bottom to the up

direction i.e. from derived class to the parent class.Generalization is the relationship between a class (superclass) and one or

more variations of the class (subclasses).A superclass holds common attributes, attributes and associations.The subclasses adds specific attributes, operations, and associations. They

inherit the features of their superclass.Generalization is called a “IS A” relationship

Page 106: Unit  1( modelling concepts & class modeling)

• It is represented by a solid line with a large arrow head pointing towards the parent class.

• Example:

106

Vehicle

Car Truck

Page 107: Unit  1( modelling concepts & class modeling)

Generalization

Customer

Corporate

Customer

Personal

Customer

Page 108: Unit  1( modelling concepts & class modeling)

Software Design (UML)

Generalization Relationships

Person

A generalization connects a subclassto its superclass. It denotes an inheritance of attributes and behaviorfrom the superclass to the subclass andindicates a specialization in the subclassof the more general superclass.

Student

Page 109: Unit  1( modelling concepts & class modeling)

109

Generalization Relationships

Vehicle

Bus Truck Car

Boeing 737

BoeingAirplane

Boeing 757 Boeing 767

Page 110: Unit  1( modelling concepts & class modeling)

Subtype2

Supertype

Subtype1

-

Regular Customer

Loyalty Customer

Customer Example:

Page 111: Unit  1( modelling concepts & class modeling)
Page 112: Unit  1( modelling concepts & class modeling)

Figure 5-10. An example of a generalization hierarchy (UML class diagram). The root of the hierarchy represents the most general concept, whereas the leaves nodes represent the most specialized concepts.

Incident

LowPriority Emergency Disaster

EarthQuake ChemicalLeakCatInTree

TrafficAccident BuildingFire

Page 113: Unit  1( modelling concepts & class modeling)

Use of generalization

Used for three purposes:Support of polymorphism:

polymorphism increases the flexibility of software.

Adding a new subclass and automatically inheriting superclass behavior.

Structuring the description of objects:

Forming a classification, organizing objects according to their similarities. It is much more profound than modeling each class individually and in isolation of other similar classes.

Enabling code reuse:

Reuse is more productive than repeatedly writing code from scratch.

Page 114: Unit  1( modelling concepts & class modeling)

Generalization, Specialization, and Inheritance

The terms generalization, specialization, and inheritance all refer to aspects of the same idea.

Generalization and specialization concern a relationship among classes and take opposite perspectives, viewed from the superclass or from the subclasses.

Generalization derives from the fact that the superclass generalizes the subclasses

Specialization refers to the fact that the subclasses refine or specialize the superclass.

Inheritance is the mechanism for sharing attributes, operations, and associations via the generalization/specialization relationship. Generalization represents a relationship at the conceptual level Inheritance is an implementation technique

Page 115: Unit  1( modelling concepts & class modeling)

115

Person

attributes

operations

Poor Generalization Example(violates the “is a” or “is a kind of” heuristic)

Arm

attributes

operations

Leg

attributes

operations

Head

attributes

operations

Page 116: Unit  1( modelling concepts & class modeling)
Page 117: Unit  1( modelling concepts & class modeling)
Page 118: Unit  1( modelling concepts & class modeling)
Page 119: Unit  1( modelling concepts & class modeling)
Page 120: Unit  1( modelling concepts & class modeling)
Page 121: Unit  1( modelling concepts & class modeling)

Class model for managing credit card accounts

MailingAddress

addressphoneNumber

CreditCardAccount

maximumCreditcurrentBalance

statementDate

address

Institution

name

phoneNumber

accountNumber

Customername

Statement

paymentDueDate

financeCharge

minimumPayment

Transaction

transactionDate

explanation

amount

transactionNumber

Interest PurchaseCashAdvance Fee

feeType

Adjustment

Merchant

name

1 *

*

*

0..1 1

1 0..1

*

1

accountHolder

Page 122: Unit  1( modelling concepts & class modeling)

122

Overloading vs. OverridingOverloading deals with

multiple methods in the same class with the same name but different signatures

Overloading lets you define a similar operation in different ways for different data

Overriding deals with two methods, one in a parent class and one in a child class, that have the same signature

Overriding lets you define a similar operation in different ways for different object types