material available on web at - vijay vora | (assist. prof. at … ·  · 2011-09-042011-09-04 ·...

100
Material available on web at Material available on web at http://vijayvorafrommgi.wordpress.com

Upload: danghanh

Post on 02-May-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Material available on web atMaterial available on web athttp://vijayvorafrommgi.wordpress.com

•• IntroductionIntroduction–– An object modeling is an abstraction An object modeling is an abstraction

(concept/idea/thought) of something for the (concept/idea/thought) of something for the

purpose of understanding it before building it..purpose of understanding it before building it..

by:-Assist. Prof. Vijay Vora

(SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

2

Modeling as a Modeling as a

design techniquedesign techniquedesign techniquedesign technique

••ModelingModeling–– Before construction things, designers build many Before construction things, designers build many

kinds of models for various purposes.kinds of models for various purposes.

��Purposes of modelingPurposes of modeling

––Testing a physical entity before building itTesting a physical entity before building it

––communication with customers communication with customers

––Visualization Visualization

––Reduction of complexityReduction of complexity

by:-Assist. Prof. Vijay Vora

(SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

4

––Testing a physical entity before Testing a physical entity before

building itbuilding it

•• Recent advances in computation permit the Recent advances in computation permit the

simulation of many physical structures without simulation of many physical structures without

the need to build physical models.the need to build physical models.

•• Not only is simulation cheaper, but it provides Not only is simulation cheaper, but it provides •• Not only is simulation cheaper, but it provides Not only is simulation cheaper, but it provides

information that is too brief and inaccessible to information that is too brief and inaccessible to

be measured from a physical model.be measured from a physical model.

by:-Assist. Prof. Vijay Vora

(SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

5

––Communication with customersCommunication with customers

•• architects and product designer build models architects and product designer build models

to show their customers and communicate to show their customers and communicate

with customers about product.with customers about product.

––Visualization Visualization

•• Architects or product designer sketches their Architects or product designer sketches their •• Architects or product designer sketches their Architects or product designer sketches their

ideas, visualized it and see how their ideas ideas, visualized it and see how their ideas

flow.flow.

•• They can modify uncomfortable transitions, They can modify uncomfortable transitions,

unnecessary segments before actual task unnecessary segments before actual task

begins.begins.

by:-Assist. Prof. Vijay Vora

(SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

6

––Reduction of complexityReduction of complexity

•• The main reason for modeling is to deal The main reason for modeling is to deal

with systems that are too complex to with systems that are too complex to

understand directly.understand directly.

•• The human mind can cope with only a The human mind can cope with only a

limited amount of information at one time.limited amount of information at one time.limited amount of information at one time.limited amount of information at one time.

•• Models reduce complexity by separating Models reduce complexity by separating

out a small number of important things to out a small number of important things to

deal with at a time.deal with at a time.

by:-Assist. Prof. Vijay Vora

(SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

7

••AbstractionAbstraction–– Abstraction is one of the fundamental ways that Abstraction is one of the fundamental ways that

humans manage with complexity.humans manage with complexity.

–– The goal of abstraction is to isolate those aspects The goal of abstraction is to isolate those aspects

that are important for some purpose and that are important for some purpose and

suppress those aspect that are unimportant.suppress those aspect that are unimportant.suppress those aspect that are unimportant.suppress those aspect that are unimportant.

––Many different abstractions of the same thing are Many different abstractions of the same thing are

possible, depending on the purpose for which possible, depending on the purpose for which

they are made.they are made.

–– All abstraction are incomplete and inaccurate.All abstraction are incomplete and inaccurate.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 8

••The three modelsThe three models–– To model a system there are different three To model a system there are different three

viewpoints.viewpoints.

••Class modelClass model

••State modelState model••State modelState model

•• Interaction modelInteraction model

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 9

••Class modelClass model–– Describes the structure of objects in a system Describes the structure of objects in a system ––

their identity, their relationship to other object, their identity, their relationship to other object,

their attributes and their operations.their attributes and their operations.

–– It provides context for the state model and It provides context for the state model and

interaction modelinteraction model

–– Goal of constructing a class model is to capture Goal of constructing a class model is to capture

those concepts from the real world that are those concepts from the real world that are

important to an application.important to an application.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 10

••State modelState model–– Describes those aspects of objects concerned with Describes those aspects of objects concerned with

time and the sequencing of operations time and the sequencing of operations –– events events

that mark changes, states that define the context that mark changes, states that define the context

(background) for events, and the organization of (background) for events, and the organization of

events and states.events and states.

–– The state model captures control, the aspect of a The state model captures control, the aspect of a –– The state model captures control, the aspect of a The state model captures control, the aspect of a

system that describes the sequences of operations system that describes the sequences of operations

that occur, without regard for what the operation that occur, without regard for what the operation

do, what they operate on, or how they are do, what they operate on, or how they are

implemented.implemented.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 11

•• Interaction modelInteraction model

–– Describes interaction between object Describes interaction between object –– how how

individual objects collaborate to achieve the individual objects collaborate to achieve the

behavior of the system as a whole.behavior of the system as a whole.

–– Use cases, sequence diagrams, and activity Use cases, sequence diagrams, and activity

diagrams document the interaction modeldiagrams document the interaction model

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 12

Class ModelingClass Modeling--

Object and ClassesObject and ClassesObject and ClassesObject and Classes

••OObject and class conceptbject and class concept••ObjectObject

••ClassesClasses

••Class diagramClass diagram

••Values and attributesValues and attributes••Values and attributesValues and attributes

••Operations and methodsOperations and methods

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 14

•• ObjectObject–– The purpose of class modeling is to describe objects.The purpose of class modeling is to describe objects.

–– An object is a concept, abstraction or thing with An object is a concept, abstraction or thing with identity that has meaning for an application.identity that has meaning for an application.

–– Some objects have realSome objects have real--world counterparts, while world counterparts, while others are conceptual entitiesothers are conceptual entities

•• ClassesClasses–– An object is an instance of or occurrence of a classAn object is an instance of or occurrence of a class–– An object is an instance of or occurrence of a classAn object is an instance of or occurrence of a class

–– A class describes a group of objects with the same A class describes a group of objects with the same properties (attributes), behavior (operations), kinds properties (attributes), behavior (operations), kinds of relationships, and semantics.of relationships, and semantics.

–– Classes often appear as common nouns and noun Classes often appear as common nouns and noun phrases in problem descriptions and discussions with phrases in problem descriptions and discussions with users.users.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 15

•• Class diagramClass diagram–– Class diagrams provide a graphic notation for Class diagrams provide a graphic notation for

modeling classes and their relationships, thereby modeling classes and their relationships, thereby describing possible objects.describing possible objects.

–– Class diagram are useful both for abstract modeling Class diagram are useful both for abstract modeling and for designing actual programs.and for designing actual programs.

•• Values and attributesValues and attributes––Value Value ––Value Value

• A value is a piece of data.

––AttributeAttribute

• An attribute is a named property of a class that describes a value held by each object of the class.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 16

••Operations and methodsOperations and methods––OperationOperation

• An operation is a function or procedure that may be applied to or by objects in class.

• All objects in a class share the same operations.

• Each operation has a target object as an implicit argument.

––Method Method

• A method is the implementation of an operation for a class.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 17

AssociationAssociationAssociationAssociation

•• Links and associationsLinks and associations–– LinkLink

• A link is an instance of an associations.

• A link is a physical or conceptual connection among objects.

• For e.g. Mr. Abc WorksFor XYZ company

• Mathematically link define as a tuple (record) i.e. a list of object

–– AssociationAssociation

• An association is a description of a group of links with • An association is a description of a group of links with common structure and common semantics (meaning).

• For e.g. a person WorksFor a company.

• The links of an association connect objects from the same classes.

• For each association there is at most one link between a given pair of objects, if there is a two links between the same object , than it must have two associations.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 19

••MultiplicityMultiplicity––Multiplicity specifies the number of Multiplicity specifies the number of

instances of one class that may relate to a instances of one class that may relate to a single instance of an associated class.single instance of an associated class.

––Multiplicity constrains (limits) the number Multiplicity constrains (limits) the number of related objects.of related objects.of related objects.of related objects.

–– It is a subset of the nonnegative integers.It is a subset of the nonnegative integers.

––Sometimes “multiplicity” and “cardinality” Sometimes “multiplicity” and “cardinality” create confutation in meaning.create confutation in meaning.• Multiplicity : it is a constraint on the size of collection

• Cardinality : it is the count of element that are actually in a collection.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 20

••Association end names Association end names

[names of association end][names of association end]––The notion (concept) of an The notion (concept) of an association end association end

is an important concept in the UMLis an important concept in the UML

––One can assign a multiplicity as well as a One can assign a multiplicity as well as a ––One can assign a multiplicity as well as a One can assign a multiplicity as well as a name to an association end.name to an association end.

––Use of association end names is optional, Use of association end names is optional, but it is often easier and less confusing to but it is often easier and less confusing to assign association end names instead of assign association end names instead of association namesassociation names

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot) 21

•• OOrderingrdering

–– Often the objects on a “many” association end Often the objects on a “many” association end

have no explicit order and one can regard them have no explicit order and one can regard them

as a set.as a set.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)22

•• Bags and sequencesBags and sequences

–– Binary association has at most one link for a pair of Binary association has at most one link for a pair of objects by annotating (explaining) an association objects by annotating (explaining) an association end with end with {bag}{bag} or or {sequence}{sequence}..

–– BagBag

• A bag is a collection of elements with duplicates allowed

–– SequenceSequence

• Sequence is an ordered collection of elements with • Sequence is an ordered collection of elements with duplicates allowed

• One should know that the pair of objects has at most one link

–– But some modelers misunderstood that association But some modelers misunderstood that association constructed with multiple links is incorrect model. constructed with multiple links is incorrect model.

–– In fact, if model specify {bag} or {sequence} then In fact, if model specify {bag} or {sequence} then there can be multiple links for a pair of objects.there can be multiple links for a pair of objects.by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

23

•• Association classesAssociation classes

–– Association classes represents the information Association classes represents the information

which describe the object of a class with which describe the object of a class with

attributes and also describe the links of an attributes and also describe the links of an

association with attributes.association with attributes.

–– Association class is an association that is also a Association class is an association that is also a

classclassclassclass

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)24

•• Qualified AssociationsQualified Associations

–– A Qualified Association is an association in which A Qualified Association is an association in which

an attribute disambiguates the objects for a an attribute disambiguates the objects for a

“many” association end.“many” association end.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)25

GeneralizationGeneralizationGeneralizationGeneralization

•• DefinitionDefinition

–– Generalization is the relationship between a class Generalization is the relationship between a class (the super classes) and one or more variations of (the super classes) and one or more variations of the class (the subclasses).the class (the subclasses).

–– Generalization organizes classes by their Generalization organizes classes by their similarities and differences, structuring the similarities and differences, structuring the description of objects.description of objects.

–– The super class holds common attributes, The super class holds common attributes, operation and associations; the sub classes add operation and associations; the sub classes add specific attributes and operation.specific attributes and operation.

–– Generalization is sometimes called the “isGeneralization is sometimes called the “is--a” a” relationship, because each instance of a subclass relationship, because each instance of a subclass is an instance of the super class as well.is an instance of the super class as well.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)27

•• Use of GeneralizationUse of Generalization

–– Generalization has three purposesGeneralization has three purposes

• Support for polymorphism

• To structure the description of objects

• To enable reuse of code

–– Generalization and SpecializationGeneralization and Specialization–– Generalization and SpecializationGeneralization and Specialization

• Generalization

• Specialization

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)28

•• OverridingOverriding

–– A subclass may A subclass may overrideoverride a a superclasssuperclass feature by feature by

defining a feature with the same name defining a feature with the same name

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)29

AggregationAggregationAggregationAggregation

•• IntroductionIntroduction

–– Aggregation is a strong form of association in Aggregation is a strong form of association in

which an aggregate object is made of constituent which an aggregate object is made of constituent

(basic) parts.(basic) parts.

–– The aggregate is semantically an extended object The aggregate is semantically an extended object

that is treated as a unit in many operations, that is treated as a unit in many operations,

although physically it is made of several lesser although physically it is made of several lesser although physically it is made of several lesser although physically it is made of several lesser

object.object.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)31

•• Aggregation vs. Association Aggregation vs. Association

–– Aggregation is a special form of association, not Aggregation is a special form of association, not

an independent concept.an independent concept.

–– If two objects are tightly bound by a partIf two objects are tightly bound by a part--whole whole

relationship, it is an aggregation.relationship, it is an aggregation.

–– If the two object are usually considered as If the two object are usually considered as

independent, even though they may often be independent, even though they may often be independent, even though they may often be independent, even though they may often be

linked, it is an association.linked, it is an association.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)32

–– There are some of the essential question that There are some of the essential question that

differentiate aggregation and associationdifferentiate aggregation and association

• Would person use the phrase part of ?

• Do some operations on the whole

automatically apply to its parts?

• Do some attribute values propagate (spread)

from the whole to all or some parts ?from the whole to all or some parts ?

• Is there an intrinsic (inherent) asymmetry

(irregularity) to the association, where one

class is subordinate to the other?

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)33

•• Aggregation vs. Composition Aggregation vs. Composition

–– The UML has two forms of partThe UML has two forms of part--whole relationship whole relationship

• Aggregation

–A general form

• Composition

–A restrictive form

–– Composition is a form of aggregation with two Composition is a form of aggregation with two –– Composition is a form of aggregation with two Composition is a form of aggregation with two additional constraints.additional constraints.

–A constituent (element) part can belong to at most one assembly

–Once a constituent part has been assigned an assembly, it has a coincident (synchronized) lifetime with the assembly.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)34

•• Propagation of OperationsPropagation of Operations

–– Propagation is the automatic application of an Propagation is the automatic application of an

operation to a network of object when the operation to a network of object when the

operation is applied to operation is applied to some starting some starting object.object.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)35

Abstract ClassesAbstract ClassesAbstract ClassesAbstract Classes

•• Abstract ClassesAbstract Classes

–– An abstract classes is a class that has no direct An abstract classes is a class that has no direct

instances but whose descendant (inheritor) instances but whose descendant (inheritor)

classes have direct instances.classes have direct instances.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)37

Multiple InheritanceMultiple InheritanceMultiple InheritanceMultiple Inheritance

•• IntroductionIntroduction

––Multiple inheritance permits a class to have more Multiple inheritance permits a class to have more

than one super class and to inherit features from than one super class and to inherit features from

all parents.all parents.

–– The terms multiple inheritance is used somewhat The terms multiple inheritance is used somewhat

imprecisely (roughly) to mean either the imprecisely (roughly) to mean either the

conceptual relationship between classes or the conceptual relationship between classes or the conceptual relationship between classes or the conceptual relationship between classes or the

language mechanism to implements that language mechanism to implements that

relationship.relationship.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)39

•• Kinds of multiple InheritanceKinds of multiple Inheritance

–– Subclass inherits from one class in each set Subclass inherits from one class in each set

disjoint classesdisjoint classes

• The most conman form of multiple

inheritance is from set of disjoint classes

• Each subclass inherits from one class in • Each subclass inherits from one class in

each set

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)40

–– In the figureIn the figure FullTimeIndividualContributor FullTimeIndividualContributor is both is both

FullTimeEmployee FullTimeEmployee and and IndividualContributorIndividualContributor and and

combines their features.combines their features.

–– FullTimeEmployee FullTimeEmployee and and PartTimeEmployee PartTimeEmployee are are

disjoint; each employee must belong to exactly one disjoint; each employee must belong to exactly one

of these.of these. by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)41

–– Subclass inherits from more than one class along Subclass inherits from more than one class along

with more than one pathwith more than one path

• A subclass inherits a feature from the

same ancestor class found along more

than one path only once; it is the same

feature.

––Multiple inheritance with overlapping classesMultiple inheritance with overlapping classes––Multiple inheritance with overlapping classesMultiple inheritance with overlapping classes

• Multiple inheritance can also occur with

overlapping classes

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)42

–– In Fig. In Fig. AmphibiousVehicleAmphibiousVehicle is both is both LandVehicleLandVehicle

and and WaterVehicleWaterVehicle..

–– LandVehicleLandVehicle and and WaterVehicle WaterVehicle overlap, because overlap, because

some vehicles travel on both land and water.some vehicles travel on both land and water.by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

43

•• Multiple classificationMultiple classification

–– An instance of a class is inherently an instance of all An instance of a class is inherently an instance of all ancestors of the class (all parent class)ancestors of the class (all parent class)

–– For example, an instructor could be both faculty and For example, an instructor could be both faculty and student.student.

–– In this, classes are overlapping but there is a loss of identity In this, classes are overlapping but there is a loss of identity between the separate role.between the separate role.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)44

•• WorkaroundsWorkarounds

–– Dealing with lack of multiple inheritance is really an Dealing with lack of multiple inheritance is really an implementation issue, but early restructuring of a model is implementation issue, but early restructuring of a model is often the easiest way to work around its absence. often the easiest way to work around its absence.

–– There is some restructuring techniques that are as underThere is some restructuring techniques that are as under

•• Delegation using composition of partsDelegation using composition of parts

•• Inherit the most important class and delegate the restInherit the most important class and delegate the rest

•• Nested generalizationNested generalization•• Nested generalizationNested generalization

•• SuperclassesSuperclasses of equal importanceof equal importance

•• Dominant Dominant superclassessuperclasses

•• Few subclassesFew subclasses

•• Sequencing generalization setsSequencing generalization sets

•• Large quantities of codeLarge quantities of code

•• IdentityIdentity

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)45

•• Delegation using composition of partsDelegation using composition of parts

––Delegation is an implementation Delegation is an implementation mechanism by which an object forwards an mechanism by which an object forwards an operation to another object for execution.operation to another object for execution.

––Delegation using composition of parts one Delegation using composition of parts one can recast a can recast a superclasssuperclass with multiple with multiple independent generalization as a independent generalization as a independent generalization as a independent generalization as a composition in which each constitution part composition in which each constitution part replace a generalization.replace a generalization.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)46

–– For example below given figure shows Workaround for For example below given figure shows Workaround for multiple inheritance multiple inheritance -- delegation.delegation.

– In this EmployeeEmploymentEmployeeEmployment become a superclass of

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)47

– In this EmployeeEmploymentEmployeeEmployment become a superclass of FullTimeEmployeeFullTimeEmployee and PartTimeEmployee.PartTimeEmployee.

–– EmployeeEmploymentEmployeeEmployment becomes a superclass of ManagerManager and IndividualContributor.IndividualContributor.

– Then one can model Employee as a composition of EmployeeEmploymentEmployeeEmployment and EmployeeManagement.EmployeeManagement.

– An operation sent to an EmployeeEmployee object would have to be redirected to the EmployeeEmploymentEmployeeEmployment or EmployeeManagement EmployeeManagement part by the EmployeeEmployee class.

•• Inherit the most important class and delegate the Inherit the most important class and delegate the

restrest

–– To workaround for multiple inheritance, inherit To workaround for multiple inheritance, inherit the most important class and delegate the rest.the most important class and delegate the rest.

–– Above figure preserves identity and inheritance Above figure preserves identity and inheritance across the most important generalization.across the most important generalization.

––Degrade (corrupt) the remaining generalizations Degrade (corrupt) the remaining generalizations to composition and delegate their operation as to composition and delegate their operation as in the previous alternative.in the previous alternative.by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

48

•• Nested generalizationNested generalization

––Nested generalization means factor on one Nested generalization means factor on one generalization first, then the other.generalization first, then the other.

–– This approach multiplies out all possible This approach multiplies out all possible combinations.combinations.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)49

–– Figure shows nested generalizationFigure shows nested generalization

–– In this In this FullTimeEmployee FullTimeEmployee and and PartTimeEmployee, PartTimeEmployee, add two subclasses for managers and individual add two subclasses for managers and individual contributors.contributors.

–– This preserves inheritance but duplications This preserves inheritance but duplications declarations and code and violates the spirit of OO declarations and code and violates the spirit of OO programming.programming.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)50

•• SuperclassesSuperclasses of equal importanceof equal importance–– If a subclass has several If a subclass has several superclassessuperclasses, all of , all of

equal importance, it may be best to use equal importance, it may be best to use delegation and preserve symmetry in the delegation and preserve symmetry in the model.model.

•• Dominant Dominant superclassessuperclasses–– if one if one superclasssuperclass clearly dominate and the clearly dominate and the

other are less important, preserve inheritance other are less important, preserve inheritance –– if one if one superclasssuperclass clearly dominate and the clearly dominate and the

other are less important, preserve inheritance other are less important, preserve inheritance through this less important path.through this less important path.

•• Few subclassesFew subclasses–– If the number of combinations is small, If the number of combinations is small,

consider nested generalization.consider nested generalization.

–– If the number of combinations is large, avoid If the number of combinations is large, avoid it.it. by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)

51

•• Sequencing generalization setsSequencing generalization sets

–– If person use nested generalization, factor on If person use nested generalization, factor on the most important criterion first, the next the most important criterion first, the next most important second and so forth.most important second and so forth.

•• Large quantities of codeLarge quantities of code

–– Try to avoid nested generalization if user must Try to avoid nested generalization if user must duplicate large quantities of code.duplicate large quantities of code.––

duplicate large quantities of code.duplicate large quantities of code.

•• IdentityIdentity

–– Consider the importance of maintaining strict Consider the importance of maintaining strict identity.identity.

––Only nested generalization preserves this Only nested generalization preserves this

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)52

MetadataMetadataMetadataMetadata

•• MetadataMetadata–– Metadata Metadata is data that describes other data.is data that describes other data.

–– For instance, a class definition is metadata.For instance, a class definition is metadata.

–– Models are inherently metadata, because they describe Models are inherently metadata, because they describe

the thing being modeled.the thing being modeled.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)54

–– Classes are metaClasses are meta--objects.objects.

–– Class descriptor object have features, and they in turn Class descriptor object have features, and they in turn

have their own classes, which are called have their own classes, which are called metaclassesmetaclasses..

Reification Reification Reification Reification

•• ReificationReification

–– Reification Reification is the promotion (promote) of something that is is the promotion (promote) of something that is not an object into an object.not an object into an object.

–– Reification is a helpful technique for meta applications.Reification is a helpful technique for meta applications.

–– It is useful to promote attributes, methods, constraints, and It is useful to promote attributes, methods, constraints, and control information into objects so one can describe and control information into objects so one can describe and manipulate them as data. manipulate them as data.

–– As an example of reificationAs an example of reification

• Consider a data manager.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)56

• Consider a data manager.

• A developer could write code for each application so that it can read and write from files.

• Instead it is a better idea to reify the notion (opinion) of data services and use a database manager.

• A database manager has abstract functionality that provides a general-purpose solution to accessing data reliably and quickly for multiple users.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)57

Constraints Constraints Constraints Constraints

•• ConstraintsConstraints

–– A A constraint constraint is a is a booleanboolean condition involving model condition involving model

elements.elements.

–– Model elements are objects, classes, attributes, links, Model elements are objects, classes, attributes, links,

associations, and generalization sets.associations, and generalization sets.

–– A constraint restricts the values that elements can A constraint restricts the values that elements can

assume.assume.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)59

–– Types of constraints on model elementsTypes of constraints on model elements

•• Constraints on objectsConstraints on objects

•• Constrains on generalization setsConstrains on generalization sets

•• Constraints on linksConstraints on links

•• Use of constraintsUse of constraints

•• Constraints on objectsConstraints on objects–– The structure of a model express many constraints, but The structure of a model express many constraints, but

sometimes it is helpful to add explicit constraints on sometimes it is helpful to add explicit constraints on

object.object.

–– Example of constraints.Example of constraints.

• No employee’s salary can exceed the salary of

the employee’s boss.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)60

the employee’s boss.

•• Constrains on generalization setsConstrains on generalization sets–– Class models capture many constraints through their different Class models capture many constraints through their different

structure of generalization.structure of generalization.

–– The UML defines the keywords for generalization sets.The UML defines the keywords for generalization sets.

•• Disjoint : Disjoint :

–The subclasses are mutually exclusive.

–Each object belongs to exactly one of the sub-classes

•• OverlappingOverlapping

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)61

•• OverlappingOverlapping

•• Complete Complete

–The generalization lists all the possible subclasses

•• IncompleteIncomplete

–The generalization may be missing some subclasses

•• Constraints on linksConstraints on links–– Multiplicity is a constraints on the cardinality of a set.Multiplicity is a constraints on the cardinality of a set.

–– Multiplicity for an association restricts the number of Multiplicity for an association restricts the number of

objects related to given object.objects related to given object.

–– Qualification also constraints an association .Qualification also constraints an association .

–– A qualifier attribute does not only describe the links of A qualifier attribute does not only describe the links of

an association but also significant in resolving the an association but also significant in resolving the

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)62

an association but also significant in resolving the an association but also significant in resolving the

“many” objects at an association end.“many” objects at an association end.

•• Use of constraintsUse of constraints–– Constraints provide one criterion for measuring the Constraints provide one criterion for measuring the

quality of a class model; a “good” class model captures quality of a class model; a “good” class model captures

many constraints through its structure.many constraints through its structure.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)63

Derived Data Derived Data Derived Data Derived Data

•• Derived DataDerived Data

–– A A Derived Element Derived Element is a function of one or more is a function of one or more

elements, which in turn may be derived.elements, which in turn may be derived.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)65

–– Figure shows a derived attribute.Figure shows a derived attribute.

–– In that, age can be derived from birthDate and the In that, age can be derived from birthDate and the

current datacurrent data

•• PackagesPackages

–– A A Package Package is a group of elements with a common is a group of elements with a common

theme.theme.

–– A package partitions a model, making it easier to A package partitions a model, making it easier to

understand and manage.understand and manage.

–– Large applications may require several tiers of packages.Large applications may require several tiers of packages.

–– The figure shows notation for a package.The figure shows notation for a package.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)66

–– The figure shows notation for a package.The figure shows notation for a package.

•• TTips for devising packagesips for devising packages

––Carefully define each package’s scope Carefully define each package’s scope

• The precise (accurate) boundaries of a package

are a matter of judgment.

––Define each class in a single packageDefine each class in a single package

• The defining package should show the class

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)67

• The defining package should show the class

name, attributes and operations.

––Make packages cohesive (interconnected)Make packages cohesive (interconnected)

• Association and generalization should normally

appear in a single package, but classes can

appear in multiple packages, helping to bind

them.

State ModelingState Modeling--State State State ModelingState Modeling--State State

•• SState Modelingtate Modeling--State State

–– It contain two thingsIt contain two things

•• EventsEvents

•• States States

•• EventsEvents–– An An Event Event iaia an occurrence at a point in time, such as an occurrence at a point in time, such as user user

depresses left button depresses left button or likewiseor likewise

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)69

depresses left button depresses left button or likewiseor likewise

–– Two events that are causally unrelated are said to be Two events that are causally unrelated are said to be Concurrent; Concurrent; they have no effect on each other.they have no effect on each other.

–– Types of Events Types of Events

••Signal eventsSignal events

••Change eventsChange events

••Signal eventsSignal events

–A signal is an explicit one-way transmission

of information from one object to another.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)70

••Change eventsChange events

–A change event is an events that is caused

by the satisfaction of a Boolean expression.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)71

•• States States

–– A state is an abstraction of the values and links A state is an abstraction of the values and links of an object.of an object.

–– Sets of values and links are grouped together Sets of values and links are grouped together into a state according to the gross behavior of into a state according to the gross behavior of objects.objects.

–– For example, the state of a bank is either For example, the state of a bank is either

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)72

–– For example, the state of a bank is either For example, the state of a bank is either solvent or insolvent, depending on whether its solvent or insolvent, depending on whether its assets exceed its liabilities.assets exceed its liabilities.

––UML notation for a stateUML notation for a state

––

InsolventSolvent

––The object in a class have a finite number of The object in a class have a finite number of

possible states possible states –– one or some large number.one or some large number.

––Each object can only be in one state at a Each object can only be in one state at a

time.time.

––Object may processed through one or more Object may processed through one or more

states during their lifetime.states during their lifetime.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)73

states during their lifetime.states during their lifetime.

––For example…For example…

• If a digit is dialed in state Dial tone, the phone line

drops the dial tone and enters state Dialing; if the

receiver is replaced in state Dial tone, the phone line

goes dead and enters state Idle.

––There is a certain symmetry between events There is a certain symmetry between events

and states,and states,

• Events represent points in time

• States represent intervals of time.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)74

––One can characterize a state in various ways One can characterize a state in various ways

which shows in below figure which shows in below figure

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)75

Transitions and Transitions and Conditions Conditions Conditions Conditions

•• TTransitions ransitions

–– A A Transition Transition is an immediate change from one state to is an immediate change from one state to

another.another.

–– For example. When a called phone is answered, the For example. When a called phone is answered, the

phone line transitions from the phone line transitions from the Ringing Ringing state to the state to the

Connected Connected state.state.

–– The transition is said to The transition is said to firefire upon the change from the upon the change from the

source state to the target state.source state to the target state.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)77

source state to the target state.source state to the target state.

•• ConditionCondition

–– A guard condition is a A guard condition is a booleanboolean expression that must be expression that must be

true in order for a transition to occur .true in order for a transition to occur .

–– For example, a traffic light at an intersection may change For example, a traffic light at an intersection may change

only if a road has car waiting.only if a road has car waiting.

–– Figure show guarded transitions for traffic lights at an Figure show guarded transitions for traffic lights at an intersection.intersection.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)78

–– One pair of electric eyes checks the northOne pair of electric eyes checks the north--south left turn south left turn lanes;lanes;

–– Another pair checks the eastAnother pair checks the east--west turn lanes.west turn lanes.

–– In no car is in the northIn no car is in the north--south and/or east/west turn lanes, south and/or east/west turn lanes, then the traffic light control logic is smart enough to skip the then the traffic light control logic is smart enough to skip the left turn portion of cycleleft turn portion of cycle

State Diagrams State Diagrams State Diagrams State Diagrams

–– A A State Diagram State Diagram is a graph whose nodes are states and is a graph whose nodes are states and

whose directed arcs are transitions between states.whose directed arcs are transitions between states.

–– A state diagrams specifies the state sequences caused by A state diagrams specifies the state sequences caused by

event sequences.event sequences.

–– State names must be unique within the scope of a state State names must be unique within the scope of a state

diagram.diagram.

•• Basic state diagram notationBasic state diagram notation

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)80

[self study]

•• Sample state diagramSample state diagram

–– Figure shows a state diagram for a telephone line.Figure shows a state diagram for a telephone line.

–– The diagram concerns a phone line and not the caller The diagram concerns a phone line and not the caller

nor nor calleecallee..

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)81

•• One shot state diagramOne shot state diagram

–– Sate diagrams can represent continuous loops or oneSate diagrams can represent continuous loops or one--

shot life cycles.shot life cycles.

–– The diagram for the phone line is a continuous loop.The diagram for the phone line is a continuous loop.

–– OneOne--shot state diagrams represent objects with finite shot state diagrams represent objects with finite

lives and have initial and final states. lives and have initial and final states.

–– The initial state is entered on creation of an object; entry The initial state is entered on creation of an object; entry

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)82

–– The initial state is entered on creation of an object; entry The initial state is entered on creation of an object; entry

of the final state implies destruction of the object.of the final state implies destruction of the object.

–– Below given figure shows a simplified life cycle of a chess Below given figure shows a simplified life cycle of a chess

game with a default initial state (solid circle) and a game with a default initial state (solid circle) and a

default final state (bull’s eye)default final state (bull’s eye)

–– Below figure shows oneBelow figure shows one--shot diagrams by using entry shot diagrams by using entry

and exit pointand exit point

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)83

and exit pointand exit point

Nested State Nested State Diagrams Diagrams Diagrams Diagrams

•• PProblem with flat state diagram roblem with flat state diagram

–– State diagrams have often been criticized because they State diagrams have often been criticized because they

allegedly (intentionally) are impractical (unreasonable) allegedly (intentionally) are impractical (unreasonable)

for large problemsfor large problems

–– This problem is due to the flat and unstructured This problem is due to the flat and unstructured

diagrams.diagrams.

–– Consider the state diagram in below figure in which nConsider the state diagram in below figure in which n22

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)85

–– Consider the state diagram in below figure in which nConsider the state diagram in below figure in which n

transitions are needed to connect every state to every transitions are needed to connect every state to every

other stateother state

––

•• Expanding Expanding statestate

–– One way to organize a model is by having a highOne way to organize a model is by having a high--level level

diagram with subdiagram with sub--diagrams expanding certain states.diagrams expanding certain states.

–– Below given figure shows simplify state diagram by using Below given figure shows simplify state diagram by using

subdiagramssubdiagrams

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)86

–– this is the state diagram for a vending machine.this is the state diagram for a vending machine.

– Next figure elaborates the dispense dispense sate with a lower-

level state diagram called a submachine.

– A submachine is a state diagram that may be invoked as

part of another state diagram.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)87

Nested StateNested StateNested StateNested State

•• NNested Statesested States

–– One can structure states more deeply than just replacing One can structure states more deeply than just replacing

a state with a submachine.a state with a submachine.

–– Figure simplifies the phone line model from a single Figure simplifies the phone line model from a single

transition from transition from ActiveActive to to IdleIdle

–– Active Active replaces the transitions from each state to replaces the transitions from each state to Idle.Idle.

–– All the original states except All the original states except Idle Idle are nested states of are nested states of

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)89

–– All the original states except All the original states except Idle Idle are nested states of are nested states of

Active.Active.

–– The occurrence of event The occurrence of event onHookonHook in any nested state in any nested state

causes a transition to state causes a transition to state Idle.Idle.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)90

–– Below given figure shows a state diagram for an Below given figure shows a state diagram for an

automatic transmission.automatic transmission.

–– The The trandmissiontrandmission can be reverse, neutral or forward;can be reverse, neutral or forward;

–– If it is in forward, it can be in first, second or third gear.If it is in forward, it can be in first, second or third gear.

–– States States First, Second First, Second and and Third Third are nested states of state are nested states of state

Forward.Forward.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)91

Signal GeneralizationSignal GeneralizationSignal GeneralizationSignal Generalization

•• Signal GeneralizationSignal Generalization

–– One can organize signal into a generalization hierarchy One can organize signal into a generalization hierarchy

with inheritance of signal attributes.with inheritance of signal attributes.

–– Figure shows part of a tree of input signals for a Figure shows part of a tree of input signals for a

workstation.workstation.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)93

ConcurrencyConcurrencyConcurrencyConcurrency

•• ConcurrencyConcurrency–– The state model implicitly supports concurrency among The state model implicitly supports concurrency among

objects.objects.

–– Objects are autonomous (independent) entities that can act Objects are autonomous (independent) entities that can act and change state independent of one another.and change state independent of one another.

•• Aggregation concurrency Aggregation concurrency –– A state diagram for an assembly is a collection of state A state diagram for an assembly is a collection of state

diagrams, one for each part.diagrams, one for each part.

–– The aggregate state corresponds to the combined states of The aggregate state corresponds to the combined states of

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)95

–– The aggregate state corresponds to the combined states of The aggregate state corresponds to the combined states of all the parts.all the parts.

–– Aggregation is the “andAggregation is the “and--relationship”.relationship”.

–– The aggregate state is one state from the first diagram, The aggregate state is one state from the first diagram, and and a a state from the second diagram, state from the second diagram, and and a state from each other a state from each other diagram.diagram.

–– The transaction for one object can depend on another object The transaction for one object can depend on another object being in a given state.being in a given state.

–– This allows interaction between the state diagrams, while This allows interaction between the state diagrams, while preserving modularity.preserving modularity.

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)96

–– In above figure state of 1 is defined by state of 2 and of 3In above figure state of 1 is defined by state of 2 and of 3

–– In figure shows the state of In figure shows the state of Car Car as an as an aggragationaggragation of part of part states :states :

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)97

states :states :

• Ignition

• Transmission

• Accelerator

• Brake

–– The state of the car includes one state from each partThe state of the car includes one state from each part

–– The state of the car includes one state from each partThe state of the car includes one state from each part–– The state of the car includes one state from each partThe state of the car includes one state from each part

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)98

•• Concurrency within an objectConcurrency within an object

•• Synchronization if Concurrency activitySynchronization if Concurrency activity

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)99

TThank Youhank You

by:-Assist. Prof. Vijay Vora (SOOADM) MCA-III(Murlidhar Group of Institutions,Bhavnagar Road , Rajkot)100

Lecture note available on webLecture note available on webhttp://vijayvorafrommgi.wordpress.com