2. Review of OO Paradigm and UML UML-1 Venkat Subramaniam - - PDF document

2 review of oo paradigm and uml
SMART_READER_LITE
LIVE PREVIEW

2. Review of OO Paradigm and UML UML-1 Venkat Subramaniam - - PDF document

2. Review of OO Paradigm and UML UML-1 Venkat Subramaniam Benefits Of OO Development Models System using Objects Small Semantic gap between reality & model Understanding the system is easier Modifications are localized


slide-1
SLIDE 1

UML-1

Venkat Subramaniam

  • 2. Review of OO Paradigm and

UML

UML-2

Venkat Subramaniam

Benefits Of OO Development

  • Models System using Objects
  • Small Semantic gap between reality &

model

  • Understanding the system is easier
  • Modifications are localized
slide-2
SLIDE 2

UML-3

Venkat Subramaniam

Object-Oriented Paradigm

Collection of Discrete Objects Data & Behavior OO Paradigm

  • Abstraction
  • Encapsulation
  • Hierarchy

– Inheritance hierarchy (“is-a”) – Part of hierarchy (“has a”)

  • Polymorphism

UML-4

Venkat Subramaniam

Abstraction

“A simplified description ...

  • f a system that emphasizes some of the

system’s details ... while suppressing

  • thers”

“An abstraction denotes the essential characteristics of an object that distinguish it from all other kind of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer”

slide-3
SLIDE 3

UML-5

Venkat Subramaniam

Encapsulation

  • Information hiding
  • Interface - Implementation
  • Behavior & Data

“Encapsulation is the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation”

UML-6

Venkat Subramaniam

What is an Object?

  • “Concept, abstraction, or thing

with crisp boundary & meaning for a problem”

  • An Object has state and behavior
  • Objects receive stimuli/messages & respond
  • Receiving a stimulus, Object may change

state Examples:

kim jullie dylan charlie charlie.fly() stimulus

slide-4
SLIDE 4

UML-7

Venkat Subramaniam

What is a Class?

  • Group of Objects with similar

–properties (attributes) –behavior –relationships to other objects –semantics

  • Blueprints of Objects

dylan kim jullie charlie

Girl Boy Parrot Example

UML-8

Venkat Subramaniam

Hierarchy

“Hierarchy is a ranking of abstractions” Inheritance : expresses “is-a” or “Kind-of” relationship

  • Extensibility & Reusability

Part-of: expresses that object is an aggregate of another

slide-5
SLIDE 5

UML-9

Venkat Subramaniam

Polymorphism

Hiding alternative procedures behind a Common Interface Send a Message to an object - Polymorphism guarantees that the correct/proper implementation is invoked. Sender does not know specific class of receiver

UML-10

Venkat Subramaniam

Object Model

  • Captures static structure of system
  • Objects, relationships, attributes &
  • perations
  • Most important
  • Intuitive graphic representation
  • Valuable for communication & documentation
slide-6
SLIDE 6

UML-11

Venkat Subramaniam

Objects

  • Decomposing problem into objects

– depends on judgement & nature of problem

  • No one correct representation
  • Objects have identity

UML-12

Venkat Subramaniam

Class

  • Often appear as nouns in problem descriptions
  • Has semantic
  • Interpretation of semantics

– depends on application and matter of judgement

  • Each class may have zero, one or more
  • bjects
  • Each object knows it class
slide-7
SLIDE 7

UML-13

Venkat Subramaniam

Class Diagrams

  • Provide formal graphic notation for

modeling

  • Concise, easy to understand, practical
  • Describes many possible instances

UML-14

Venkat Subramaniam

Object Diagrams

  • Describes how set of objects relate
  • Useful for

– documenting test cases – Clarification of complex class diagrams

  • Class Diagram corresponds to infinite set
  • f object diagrams
slide-8
SLIDE 8

UML-15

Venkat Subramaniam

Notation for Classes & Objects (UML) Boy Girl Classes kelly brenda : Girl dylan Objects

UML-16

Venkat Subramaniam

Attributes

  • Data value held by objects of a class
  • Objects may have same/different values

for attribute

  • Attribute name unique within a class
  • Adjectives often represent specific

enumerated attribute values : “red car”

slide-9
SLIDE 9

UML-17

Venkat Subramaniam

Attributes...

  • Attribute is a pure data value - not an
  • bject
  • Internal identifiers must not be shown as

attributes

  • Show only important attributes

UML-18

Venkat Subramaniam

Derived Attributes

Base Attribute :

– primitive, not dependent on other attributes

Derived Attribute :

– computing not considered to change state of an object – dependent on base attributes – may be stored or computed upon a query

  • peration

Example : Area of a circle, age of a person

slide-10
SLIDE 10

UML-19

Venkat Subramaniam

Attributes Notation

PKG::ClassName

  • attrPrivate

#attrProtected +attrPublic assumedPrivateAttr attrStatic /derivedAttribute

  • attrWType : Int
  • attrWInitVal : Float = 0.0

+attr {readOnly} Society::Girl

  • age

+name {readOnly}

  • numberOfGirls

UML-20

Venkat Subramaniam

Operations & Methods

  • Operation : Function that may be applied to or by
  • bjects
  • Same Operations applying

to different classes: Polymorphic

  • Method is implementation of an operation for a class
  • Operation has a target object and may have

arguments

  • Same operations on different classes should have
  • ✁✄✂✆☎✞✝✟✁✡✠☞☛✍✌✎✂✑✏✓✒✕✔✖✝✟✂✆✌✑✗✙✘✛✚✆✌✜✁✢✠☞✁✣✏✤✝✕✌✢✏✥✠✦✌✎✏✧✝✕✌✢✏
  • Query Operation : Does not affect the state of object
  • Show only important methods
slide-11
SLIDE 11

UML-21

Venkat Subramaniam

Operation Notation

PKG::ClassName +methodPublic() #methodProtected()

  • methodPrivate()

assumedPublic() methodStatic() ~methodPackageVisible() methodWReturn() : Int finalMethod() {leaf} Society::Girl +play() ~sing() GetGirlsCount() : Int

UML-22

Venkat Subramaniam

Example with Attributes & Operations

  • seconds

+start() +stop() +reset() +getSeconds(): double StopWatch

slide-12
SLIDE 12

UML-23

Venkat Subramaniam

Associations and Links

  • Link is physical or conceptual

connection between objects

  • Link is an instance of an Association

Example: Link : Susan is-wife-of Robert Julie is-wife-of John Association: Woman is-wife-of Man Associations and Links appear as Verbs

UML-24

Venkat Subramaniam

Associations & Links...

  • Associations are bi-directional

–may be implemented as unidirectional

  • Implemented usually as pointers

– important not to think as pointers

  • Associations may be

–one-to-one –one-to-many –many-to-one –many-to-many

slide-13
SLIDE 13

UML-25

Venkat Subramaniam

Ternary & High Order Associations

Binary Association : Relates two classes Woman is-wife-of Man Ternary Association : Relates three classes Nancy is-daughter-of Susan and Robert n-ary Association : Relates n classes Higher Order Associations – complicated to draw, implement and think – try to avoid if possible

UML-26

Venkat Subramaniam

Associations Notations

Exactly One Optional One Or More Zero Or More * 0..1 1..* 0..* Many

Directed Association

*

Company Person employees worksFor employs 1..* 0..*

slide-14
SLIDE 14

UML-27

Venkat Subramaniam

Link Attributes & Association Classes

  • Attributes that belong to

association of object rather than one

  • bject
  • Link Attributes belong in Association

Classes

  • Ex: Salary received by Employee from Company
  • In an one-to-one association you may try

to make it attribute of one of the objects

–Leads to extensibility problems

UML-28

Venkat Subramaniam

Association Class Notation

Person Company

* *

Employment salary:double

slide-15
SLIDE 15

UML-29

Venkat Subramaniam

Role Names

  • Name given to either end of an

association

  • Helps to navigate from one object to

related objects

  • Helps clarify when two classes have

several associations between them

Woman Man

husband wife 0..1 married 0..1

Woman Man

husband wife married * 1 daughter children father 0..1 0..1

UML-30

Venkat Subramaniam

Qualifiers

  • Distinguishes among set of associated
  • bjects
  • Models associative arrays, dictionaries
  • Qualifiers may be wrongly

modeled as attribute of associated class

GradeList code Student Qualified * 1 GradeList Student Unqualified code * *

slide-16
SLIDE 16

UML-31

Venkat Subramaniam

Aggregation & Composition

Aggregation:

  • Part-of or part-whole relationship (by

reference)

  • Example : Car has Engine and Transmission
  • Assembly of objects with aggregate and

component parts

  • Component existence may or may not depend
  • n aggregate

UML-32

Venkat Subramaniam

Aggregation & Composition...

Composition:

  • Part belongs to only one whole (by Value)
  • Part lives and dies with the whole
  • Whole cannot replace the part
slide-17
SLIDE 17

UML-33

Venkat Subramaniam

Aggregation/ Composition Notation

Aggregation

Has By Value Has By Reference

+drive() Vehicle Engine VIN

UML-34

Venkat Subramaniam

Aggregation / Composition Example

Person brain Car

Aggregation Composition

slide-18
SLIDE 18

UML-35

Venkat Subramaniam

Inheritance

  • Models is-a relationship
  • Relationship between a class and its

refined versions

  • Superclass or Base class
  • Subclass or Derived class
  • Inheritance is transitive
  • Discriminator : The property being

abstracted by a particular inheritance

  • Breath Vs. Depth of inheritance

UML-36

Venkat Subramaniam

+drive() Vehicle

  • sunRoof

Car Truck

Inheritance Notation

Generalization

Subclass1 Subclass2 Superclass

slide-19
SLIDE 19

UML-37

Venkat Subramaniam

Inheritance Example

Child Animal Girl Boy Dog Cat

UML-38

Venkat Subramaniam

Grouping Mechanism : Package

  • Grouping classes together into higher-leve

units

  • Package diagram with dependency
  • Dependency between packages exists if

– class in one package depends on a class in the

  • ther

– definition change of one package may change

  • ther
slide-20
SLIDE 20

UML-39

Venkat Subramaniam

Package Notation

componentName

VehicleComponent EngineComponent Accessories UML-40

Venkat Subramaniam

Aggregation Vs. Association

  • Special form of Association
  • Confusing
  • Aggregation represents “part-of”

relationship

  • Some operations on whole automatically

applied to its parts

  • Aggregate is asymmetric :

part is subordinate to the whole

  • Association is symmetric :
  • bjects involved are of equal stature
slide-21
SLIDE 21

UML-41

Venkat Subramaniam

Aggregation Vs. Inheritance

  • Aggregation represents part-of

relationship

  • Inheritance represents kind-of

relationship

  • Aggregation refers to object

relationships

  • Inheritance refers to class relationships

UML-42

Venkat Subramaniam

Fixed, Variable & Recursive Aggregates

Fixed : – Fixed structure – Number & types of parts pre-defined Variable : – Finite number of levels - Number of parts vary Recursive : – Contains instances of the same kind of aggregate – number of potential levels unlimited

slide-22
SLIDE 22

UML-43

Venkat Subramaniam

Example : Fixed, Variable, Recursive Aggregation

Layout ElectronicComponent NAND AND FlipFlop * 2 * UML-44

Venkat Subramaniam

Operations & Aggregation

  • Operation or Triggering :

– automatic application of an operation to network of objects when applied to some starting object

  • ShallowCopy
  • DeepCopy
slide-23
SLIDE 23

UML-45

Venkat Subramaniam

Abstract Classes

Representing an Abstraction that is Abstract.

  • Abstract classes represent

– concepts – not real objects

  • ABCs used only to create other

“Concrete” classes

UML-46

Venkat Subramaniam

Abstract Classes ...

Example: Shape, Employee, Animal Whether a class in Abstract or not depends on

– judgement – application on hand

slide-24
SLIDE 24

UML-47

Venkat Subramaniam

Inheritance : Extension & Restriction

Extension :

– Subclass adds new features – Subclass inherits all properties & operations

  • f ancestor

Restriction :

– Subclass constrains ancestor attributes – Subclass may not inherit all properties &

  • perations of its ancestor

– Often leads to trouble (Liskov Substitutability Principle)

UML-48

Venkat Subramaniam

Inheritance : Extension & Restriction ...

  • Proper Extension:

– A Subclass may override the internal implementation of an operation – No problem as long as external protocol remains the same

slide-25
SLIDE 25

UML-49

Venkat Subramaniam

Constraints

Restricts values that entities can assume Entity : objects, classes, attributes, associations Better to capture constraints in structure rather than using constraints constructs

ElectronicsClass Students * {E E Discipline}