www.techstudent.co.ccwww.techstudent.co.cc 11
OBJECT-ORIENTED OBJECT-ORIENTED MODELING and DESIGN MODELING and DESIGN
ininUMLUML
www.techstudent.co.ccwww.techstudent.co.cc 22
Object oriented modeling and design is a Object oriented modeling and design is a way of thinking about problems using models way of thinking about problems using models organized around real-world concepts. The organized around real-world concepts. The fundamental construct is the object, which fundamental construct is the object, which combines both data structure and behavior. OO combines both data structure and behavior. OO models are useful for understanding problems, models are useful for understanding problems, communicating with application experts, communicating with application experts, modeling enterprises, preparing documentation modeling enterprises, preparing documentation and designing programs and databases. and designing programs and databases.
www.techstudent.co.ccwww.techstudent.co.cc 33
What is Object OrientationWhat is Object Orientation
The term “Object Oriented” means that we The term “Object Oriented” means that we organize software as a collection of discrete objects organize software as a collection of discrete objects that incorporate both data structure and behavior. that incorporate both data structure and behavior.
Identity means that data is quantized into Identity means that data is quantized into discrete, distinguishable entities called OBJECTS. discrete, distinguishable entities called OBJECTS. Each object has its own inherent identity, ie two Each object has its own inherent identity, ie two objects are distinct even if all their attribute values objects are distinct even if all their attribute values are identicalare identical
www.techstudent.co.ccwww.techstudent.co.cc 44
Classification means that objects with Classification means that objects with same data structure and behavior are same data structure and behavior are grouped into a class. A class is abstraction grouped into a class. A class is abstraction that describes properties important to an that describes properties important to an application and ignores the rest. application and ignores the rest.
ObjectObject ClassClass
BicycleBicycle AttributesAttributes framesizeframesize
wheelzisewheelzise
materialmaterial
OperationsOperations shift, Move,shift, Move,
repairrepair
www.techstudent.co.ccwww.techstudent.co.cc 55
InheritanceInheritance
Sharing of attributes and operations among Sharing of attributes and operations among
classes based on a hierarchical relationship. classes based on a hierarchical relationship.
Inheritance (by D from C) is the facility by which a Inheritance (by D from C) is the facility by which a
class D has implicitly defined upon it each of the class D has implicitly defined upon it each of the
attributes and operations of class C, as if those attributes and operations of class C, as if those
attributes and operations had been defined upon attributes and operations had been defined upon
D itself. D itself.
• C is termed a super class of DC is termed a super class of D
• D is a subclass of CD is a subclass of C
www.techstudent.co.ccwww.techstudent.co.cc 66
Polymorphism Polymorphism
It is the facility by which a single operation It is the facility by which a single operation
or attribute name may be defined upon more than or attribute name may be defined upon more than
one class and may take on different one class and may take on different
implementations in each of those classes. implementations in each of those classes.
It is the property whereby an attribute or It is the property whereby an attribute or
variable may point to (hold the handle of) objects variable may point to (hold the handle of) objects
of different classes at different times. of different classes at different times. The The
same operation may behave differently for same operation may behave differently for
different classes. different classes.
www.techstudent.co.ccwww.techstudent.co.cc 77
EncapsulationEncapsulation
It is the grouping of related ideas into It is the grouping of related ideas into one unit, which can thereafter be referred one unit, which can thereafter be referred to by a single nameto by a single name..
Object oriented encapsulationObject oriented encapsulation
It is the packing of operations and attributes It is the packing of operations and attributes representing state into an object type so that representing state into an object type so that state is accessible or modifiable only via the state is accessible or modifiable only via the interface provided by the encapsulationinterface provided by the encapsulation
www.techstudent.co.ccwww.techstudent.co.cc 88
Information/Implementation hidingInformation/Implementation hiding
It is the use of encapsulation to restrict It is the use of encapsulation to restrict from external visibility certain information or from external visibility certain information or implementation decisions that are internal to the implementation decisions that are internal to the encapsulation structure.encapsulation structure.
Object identityObject identity
It is the property by which each object can be It is the property by which each object can be identified and treated as a distinct software identified and treated as a distinct software entityentity
State RetentionState Retention
It is the ability of an object to retain the state.It is the ability of an object to retain the state.
www.techstudent.co.ccwww.techstudent.co.cc 99
MessagesMessages
A message is a vehicle by which a sender A message is a vehicle by which a sender object object obj1obj1 conveys to a target object conveys to a target object obj2obj2, a , a demand for the object demand for the object obj2obj2 to apply one of to apply one of its methodsits methods
Message StructureMessage Structure
1.1. The handle of the object The handle of the object obj2obj2
2.2. The name of the operation pf The name of the operation pf obj2obj2 that that obj1obj1 wishes to executewishes to execute
3.3. Any supplementary information that Any supplementary information that obj2obj2 will will require in the execution of its operationrequire in the execution of its operation
www.techstudent.co.ccwww.techstudent.co.cc 1010
Object Oriented MethodologyObject Oriented Methodology
The process consists of building a model of an The process consists of building a model of an application and then adding the details to it during application and then adding the details to it during design. design.
System ConceptionSystem Conception: Software development : Software development begins with business analysis or users conceiving begins with business analysis or users conceiving an application and formulating tentative an application and formulating tentative requirements. requirements.
AnalysisAnalysis: The analysis scrutinizes and rigorously : The analysis scrutinizes and rigorously restates the requirements from system conception restates the requirements from system conception by constructing models. by constructing models.
www.techstudent.co.ccwww.techstudent.co.cc 1111
The analysis model has two parts. The The analysis model has two parts. The domain model, a description of the real-world domain model, a description of the real-world objects reflected within the system and the objects reflected within the system and the application model, a description of the parts of the application model, a description of the parts of the application system itself that are visible to the user.application system itself that are visible to the user.
System DesignSystem Design: The development team : The development team devise a high-level strategy (system architecture) devise a high-level strategy (system architecture) for solving the application problem. for solving the application problem.
Class designClass design: The class designer adds details : The class designer adds details to analysis model in accordance with the system to analysis model in accordance with the system design strategy. The class designer elaborates both design strategy. The class designer elaborates both domain and application objects using the same OO domain and application objects using the same OO concepts and notation.concepts and notation.
www.techstudent.co.ccwww.techstudent.co.cc 1212
ImplementationImplementation: Implementers translate the : Implementers translate the classes and relationships developed during class classes and relationships developed during class design into a particular programming language, design into a particular programming language, database or hardware. Programming should be database or hardware. Programming should be straight-forward. It is important to follow good straight-forward. It is important to follow good software engineering practice so that traceability to software engineering practice so that traceability to design is apparent and so that the system remains design is apparent and so that the system remains flexible and extensible. flexible and extensible.
The three models: The three models: We use three kinds of We use three kinds of models to describe a system from different models to describe a system from different viewpoint. viewpoint.
The The class modelclass model describes the static structure describes the static structure of the objects in a system and their relation ships. of the objects in a system and their relation ships. It defines the context for software development. It defines the context for software development.
www.techstudent.co.ccwww.techstudent.co.cc 1313
A class diagram is a graph whose nodes are A class diagram is a graph whose nodes are classes and whose arcs are relationships among classes and whose arcs are relationships among classes.classes.
The The state modelstate model describes the aspects of an describes the aspects of an object that change over time. The state model object that change over time. The state model specifies and implements control with state specifies and implements control with state diagrams. It is a graph whose nodes are states and diagrams. It is a graph whose nodes are states and whose arcs are transitions between states caused whose arcs are transitions between states caused by events.by events.
The The interaction model interaction model describes how the describes how the objects in a system cooperate to achieve broader objects in a system cooperate to achieve broader results. The interaction model starts with use cases results. The interaction model starts with use cases that are then elaborated with sequence and activity that are then elaborated with sequence and activity diagrams.diagrams.
www.techstudent.co.ccwww.techstudent.co.cc 1414
A use case focuses on the functionality of a system A use case focuses on the functionality of a system (what the system does for the user). A sequence (what the system does for the user). A sequence diagram shows the objects that interact and the diagram shows the objects that interact and the time sequences of their interactions. An activity time sequences of their interactions. An activity diagram elaborates important processing steps.diagram elaborates important processing steps.
The three models are separate parts of the The three models are separate parts of the description of a complete system but are cross-description of a complete system but are cross-linked. The class model is most fundamental, linked. The class model is most fundamental, because it is necessary to describe because it is necessary to describe whatwhat is is changing or transforming before describing changing or transforming before describing whenwhen or or howhow it changes. it changes.
www.techstudent.co.ccwww.techstudent.co.cc 1515
Object Oriented ThemesObject Oriented Themes
AbstractionAbstraction
EncapsulationEncapsulation
Combining Data and BehaviorCombining Data and Behavior
SharingSharing
Emphasis on the Essence of an ObjectEmphasis on the Essence of an Object
Synergy (combined effort)Synergy (combined effort)
www.techstudent.co.ccwww.techstudent.co.cc 1616
Introduction to Introduction to Unified Modeling LanguageUnified Modeling Language
www.techstudent.co.ccwww.techstudent.co.cc 1717
What is UML?What is UML?
UML (Unified Modeling Language) is a UML (Unified Modeling Language) is a language:language:• For specifying, visualizing, constructing, and For specifying, visualizing, constructing, and
documenting the artifacts of software systemsdocumenting the artifacts of software systems• For business modeling and other non-software For business modeling and other non-software
systemssystems UML Definition consists of:UML Definition consists of:
• UML SemanticsUML Semantics• UML Notation GuideUML Notation Guide• UML ExtensionsUML Extensions
www.techstudent.co.ccwww.techstudent.co.cc 1818
Why UML?Why UML? MotivationMotivation
• Good models are essential for communication among project teams and Good models are essential for communication among project teams and to assure architectural soundnessto assure architectural soundness
Goals in the design of the UMLGoals in the design of the UML• Provide users a Provide users a ready-to-use, expressive visual modeling languageready-to-use, expressive visual modeling language
so they can develop and exchange meaningful models.so they can develop and exchange meaningful models.• Provide Provide extensibility and specialization mechanismsextensibility and specialization mechanisms to extend the to extend the
core concepts.core concepts.• Be Be independentindependent of particular programming languages and development of particular programming languages and development
processes.processes.• Provide Provide a formal basisa formal basis for understanding the modeling language. for understanding the modeling language.• Encourage the growth of the OO tools marketEncourage the growth of the OO tools market..• Support higher-level development conceptsSupport higher-level development concepts such as collaborations, such as collaborations,
frameworks, patterns, and components.frameworks, patterns, and components.• Integrate best practicesIntegrate best practices..
www.techstudent.co.ccwww.techstudent.co.cc 1919
UML ArtifactsUML Artifacts
Use Case diagramUse Case diagram Implementation diagramsImplementation diagrams
• Component diagramComponent diagram• Deployment diagramDeployment diagram
Behavior diagramsBehavior diagrams• State chart diagramState chart diagram• Activity diagramActivity diagram• Interactive diagramInteractive diagram
Sequence diagramSequence diagram Collaboration diagramCollaboration diagram
Class diagramClass diagram
www.techstudent.co.ccwww.techstudent.co.cc 2020
Use Case DiagramUse Case Diagram
www.techstudent.co.ccwww.techstudent.co.cc 2121
Implementation DiagramImplementation Diagram
Example: Component diagram
www.techstudent.co.ccwww.techstudent.co.cc 2222
Behavior Diagram Behavior Diagram
Example: Interaction diagram
www.techstudent.co.ccwww.techstudent.co.cc 2323
Class DiagramClass Diagram
www.techstudent.co.ccwww.techstudent.co.cc 2424
Implementation Diagram Implementation Diagram
Example: Deployment diagram
www.techstudent.co.ccwww.techstudent.co.cc 2525
Class ModelingClass Modeling The purpose of the class modeling is to describe The purpose of the class modeling is to describe
objects. An object is a concept, abstraction or thing objects. An object is a concept, abstraction or thing with identity that has meaning for an application with identity that has meaning for an application objects often appear as proper nouns or specific objects often appear as proper nouns or specific references in problem descriptions. Some objects references in problem descriptions. Some objects have real-world counterparts, while others are have real-world counterparts, while others are conceptual entities. Still others are introduces for conceptual entities. Still others are introduces for implementation reasons and have no implementation reasons and have no correspondence to physical reality. The choice of correspondence to physical reality. The choice of objects depends on judgment and the nature of a objects depends on judgment and the nature of a problem.problem.
www.techstudent.co.ccwww.techstudent.co.cc 2626
The ClassThe Class
The class symbol (a) is central to any application of UML. The topmost The class symbol (a) is central to any application of UML. The topmost of the symbol’s three components shows the class name, by of the symbol’s three components shows the class name, by convention starting with an uppercase letter. This one’s imaginatively convention starting with an uppercase letter. This one’s imaginatively named named SomeClassSomeClass. .
The middle compartment shows the attributes The middle compartment shows the attributes The bottom compartment shows its operationsThe bottom compartment shows its operations
www.techstudent.co.ccwww.techstudent.co.cc 2727
The ClassThe Class
The alternative symbol for the class is (b). This The alternative symbol for the class is (b). This abbreviated symbol is handy when you want to show abbreviated symbol is handy when you want to show only a class and its name.only a class and its name.
Equivalent symbols for depicting an objectEquivalent symbols for depicting an object
www.techstudent.co.ccwww.techstudent.co.cc 2828
The AttributesThe Attributes An attribute represents information about an objectAn attribute represents information about an object
An attribute represents an abstractly defined property, independent of how that property is internally An attribute represents an abstractly defined property, independent of how that property is internally
implemented. A variable is an internal implementation mechanism.implemented. A variable is an internal implementation mechanism.
An attribute is both gettable and settable from outside the object.An attribute is both gettable and settable from outside the object.
Some attributes are read only (gettable)Some attributes are read only (gettable)
Typically the attributes are derived from othersTypically the attributes are derived from others
Eg: age of a person, capacity of a cuboidEg: age of a person, capacity of a cuboid
www.techstudent.co.ccwww.techstudent.co.cc 2929
The AttributesThe Attributes
Read only attributes can be represented with a Read only attributes can be represented with a forward slash (/) forward slash (/)
www.techstudent.co.ccwww.techstudent.co.cc 3030
The OperationsThe Operations
Operations appear in the lowest compartment with Operations appear in the lowest compartment with their full formal signature. Each of the signature their full formal signature. Each of the signature comprises the operation name, together with the comprises the operation name, together with the list of operation’s formal input and output list of operation’s formal input and output arguments. The UML standard calls for the arguments. The UML standard calls for the keywords keywords inin and and outout before each argument to before each argument to show its direction.show its direction.
www.techstudent.co.ccwww.techstudent.co.cc 3131
The OperationsThe Operations
A typical attribute require two standard operations: A typical attribute require two standard operations:
a get operation and a set operation.a get operation and a set operation.
An attribute that’s read only doesn’t need a set An attribute that’s read only doesn’t need a set
operationoperation
A few attributes call for operations that need input A few attributes call for operations that need input
arguments. Such attributes often hold data on the arguments. Such attributes often hold data on the
previous history of that attribute.previous history of that attribute.
Some operations require communication with other Some operations require communication with other
objects through message passing. objects through message passing.
www.techstudent.co.ccwww.techstudent.co.cc 3232
Overloaded OperationsOverloaded Operations
Operations that are overloaded will appear many Operations that are overloaded will appear many
times on the class diagram, each time with a times on the class diagram, each time with a
different signature.different signature.
www.techstudent.co.ccwww.techstudent.co.cc 3333
Visibility of Attributes and OperationsVisibility of Attributes and Operations
UML attaches a prefix to an attribute or operation UML attaches a prefix to an attribute or operation name to indicate the feature’s visibility. Public name to indicate the feature’s visibility. Public attributes or operations are prefixed with a plus attributes or operations are prefixed with a plus sign (+). Protected with a number sign (#) and sign (+). Protected with a number sign (#) and private with a minus sign (-).private with a minus sign (-).
www.techstudent.co.ccwww.techstudent.co.cc 3434
Class Attributes and OperationsClass Attributes and Operations
A public class attribute an d a private class A public class attribute an d a private class operationoperation
www.techstudent.co.ccwww.techstudent.co.cc 3535
Abstract Operations and ClassesAbstract Operations and Classes
An operation is abstract if it has no implementation.An operation is abstract if it has no implementation. It has an interface and a defined functionality, but It has an interface and a defined functionality, but
no implementation method with actual codeno implementation method with actual code An abstract class does not instantiate objects, An abstract class does not instantiate objects,
usually, because it has at least one abstract usually, because it has at least one abstract operation defined on it. operation defined on it.
www.techstudent.co.ccwww.techstudent.co.cc 3636
The UtilityThe Utility
The utility (utility package) is a group of procedures The utility (utility package) is a group of procedures and functions encapsulated into a single unit with a and functions encapsulated into a single unit with a set of private data. It differs from the class in that set of private data. It differs from the class in that individual objects are never instantiated from itindividual objects are never instantiated from it
The utility is like a class with no objects: its The utility is like a class with no objects: its operations are, in effect, class operations.operations are, in effect, class operations.
www.techstudent.co.ccwww.techstudent.co.cc 3737
Parameterized ClassesParameterized Classes
UML shows a parameterized class with a dotted box UML shows a parameterized class with a dotted box over the top right of the standard class symbol. Into over the top right of the standard class symbol. Into this box goes the list of formal class argumentsthis box goes the list of formal class arguments
A typical container class, which takes a class A typical container class, which takes a class formally named T as an argumentformally named T as an argument
www.techstudent.co.ccwww.techstudent.co.cc 3838
Parameterized ClassesParameterized Classes
A bound class, formed from a parameterized classA bound class, formed from a parameterized class
When an actual class, such as Car is supplied for T, When an actual class, such as Car is supplied for T,
each of the objects of that class represent a set of each of the objects of that class represent a set of
cars. The name of the bound, parameterized class cars. The name of the bound, parameterized class
is then given as is then given as Set<Car>Set<Car>
www.techstudent.co.ccwww.techstudent.co.cc 3939
Parameterized ClassesParameterized Classes
A bound class, formed from parameterized class – A bound class, formed from parameterized class – another depictionanother depiction
www.techstudent.co.ccwww.techstudent.co.cc 4040
CLASS DIAGRAMSCLASS DIAGRAMS
www.techstudent.co.ccwww.techstudent.co.cc 4141
Generalization ConceptsGeneralization Concepts
Single InheritanceSingle Inheritance Multiple InheritanceMultiple Inheritance Subclass ParitioningSubclass Paritioning Partitioning discriminatorsPartitioning discriminators
www.techstudent.co.ccwww.techstudent.co.cc 4242
Single Inheritance
www.techstudent.co.ccwww.techstudent.co.cc 4343
Single Inheritance hierarchy – Shared Target notation
www.techstudent.co.ccwww.techstudent.co.cc 4444
Single Inheritance hierarchy – Normal abbreviated notation
www.techstudent.co.ccwww.techstudent.co.cc 4545
Multiple InheritanceMultiple Inheritance
www.techstudent.co.ccwww.techstudent.co.cc 4646
Subclass Partitioning Subclass Partitioning
The term disjoint partitioning applies to two or more groups of things that are cleanly partitioned. ie no single thing can belong to more than one group at the same time.
The term incomplete partitioning means that not all of the group’s possible subgroups are included in the model. ie the group may have some members that don’t belong to any of the modeled subgroups
www.techstudent.co.ccwww.techstudent.co.cc 4747
Subclass Partitioning Subclass Partitioning
The term dynamic partitioning to a thing’s membership in more than one subgroup over time ie a thing may begin life as a member of one subgroup but later become a member of different subgroup
www.techstudent.co.ccwww.techstudent.co.cc 4848
Subclass Partitioning Subclass Partitioning
Animal’s overlapping subclasses, Herbivore and Carnivore could have a common subclass Omnivore
www.techstudent.co.ccwww.techstudent.co.cc 4949
Partitioning DiscriminatorsPartitioning Discriminators
www.techstudent.co.ccwww.techstudent.co.cc 5050
The Association Construct
Objects are often associated with, or related to, other objects.
For example: Students are ON WAITING LIST for seminars, professors INSTRUCT seminars, seminars are an OFFERING OF courses, a professor LIVES AT an address, and so on.
Associations are modeled as lines connecting the two classes whose instances (objects) are involved in the relationship. When you model associations in UML class diagrams, you show them as a thin line connecting two classes.
www.techstudent.co.ccwww.techstudent.co.cc 5151
The Association Construct
Associations can become quite complex; consequently, you can depict some things about them on your diagrams. The label, which is optional, although highly recommended, is typically one or two words describing the association. For example, professors instruct seminars.
Associations are often two-way streets. The multiplicity of the association is labeled on either end of the line, one multiplicity indicator for each direction
www.techstudent.co.ccwww.techstudent.co.cc 5252
The Association Construct
www.techstudent.co.ccwww.techstudent.co.cc 5353
The Association ConstructAssociation in UML represents a varying
population of relationship links between instances of classes.
Modeling associations is the backbone of a powerful analysis technique called information modeling
An association or relationship is usually named with a verb form in traditional information modeling
Some multiplicity may be debatable
UML doesn’t insist on a name for an association. UML doesn’t require role names either. UML modeling tools often abbreviate multiplicity like 0..*
www.techstudent.co.ccwww.techstudent.co.cc 5454
Higher-order Association
www.techstudent.co.ccwww.techstudent.co.cc 5555
Higher-order Association
www.techstudent.co.ccwww.techstudent.co.cc 5656
Whole/Part Association
UML has special notation for two who/part associations: composition and aggregation
Composition is a common structure in software systems. Eg: an e-mail missive is a composite containing a header and a few text paragraphs. In turn, the header is a composite of the sender’s name, the receiver’s address, the message title and some other e-stuff.
The composite object does not exist without its components. At any time, given component object may be part of only one composite. Composition is typically heteromeric
www.techstudent.co.ccwww.techstudent.co.cc 5757
Composition
The role of the component object in the composition appears at the component end of the association line. If the multiplicity at the composite end is not shown then it is assumed to be exactly 1. The association has no name
www.techstudent.co.ccwww.techstudent.co.cc 5858
Aggregation
Like composition aggregation is a familiar construct whereby software systems represent structures from real life. For example, a city is an aggregate of houses, a forest is an aggregate of trees etc. In other words aggregation is a group/member association.
www.techstudent.co.ccwww.techstudent.co.cc 5959
Some ObservationsAn association between the aggregate and its
constituent is denoted by a little open diamond on the aggregate end of the association line.
The classes of the aggregate and the constituent appear at the respective ends of the association line. The role of the constituent object also appears at the constituent end of the association line.
Multiplicity 0..* means a paragraph may belong to many management report at the same time and a management report may comprise many paragraphs
The ‘ordered’ property on the association reveals that the paragraphs are in a defined sequence.
www.techstudent.co.ccwww.techstudent.co.cc 6060
Assignment 1
What makes a good Model?When to apply UML?How to apply UML?