Sei sulla pagina 1di 18

OOMD

UNIT-1 NOTES

Introduction, Modeling concepts, Class Modeling


What is an Object?
An object is an entity (a thing or a concept) that can be manipulated by programming language, such as value, variable, function. What is Object orientation? The software is organized into collection of discrete objects that incorporate (add up) both as a structure and behavior. Explain the Characteristics of OO approach each with examples: OO approach includes 4 aspects: 1. Identity 2. Classification 3. Inheritance and 4. Polymorphism Identity: Data is quantized into, discrete, distinguishable entities called objects. Object has its own identity; two objects are different even if their attribute values (size, name) are same. Classification: The objects with the same data structure (attributes) and behavior (operation) are grouped into a class. Example: paragraph, Monitor A class is an abstraction that describes the properties important to the application and ignores the rest. Each object is an instance of the class. An object has its own value for each attribute but it shares the attribute names and operations with other instances of the class. Inheritance: The sharing of attributes and operations among classes based on a hierarchical relationship. A superclass has general information that the subclasses refine and elaborate. Example: Scrolling Window and Fixed Window are subclasses of window. One main advantage of OO technology. The ability to factor out common features of several classes into super classes can reduce repetition within designs and programs. Polymorphism: The same operation may behave differently for different classes. Example: Move operation. Operation: Is a procedure or transformation that an object performs or is subject to. Example: Right justify, display, and move.

Method: An implementation of an operation by a specific class. Since OO operator is polymorphic, it may have more than one method implementing it, each for a different class or the object.

Explain OO Development
Development refers to software life cycle: Analysis Design Implementation OO development is the identification and organization of application concepts, rather than final representation in a programming language. OO concepts and notation used to express a design also to provide useful documentation. Benefits Used for helping specifiers, developers, and customers express abstract concepts clearly communicate them to each other. It can serve as a medium for specification, analysis, documentation and interfacing as well as programming.

Explain OO Methodology
The process consists of building a model of an application and then adding details to it during design. The notation is used from analysis to design to implementation. Information added in one stage of development need not be lost or translated for the next stage. The Methodology has the following stages. 1. System conception: software development begins with business analysts or users conceiving an application and formulating tentative requirements. 2. Analysis: The analyst scrutinizes (study) and rigorously (strictly) restates the requirements from system conception by constructing models. The analyst must work with the requestor to understand the problem, because problem statements are rarely complete to correct. The analysis model is concise, precise abstraction of what the desired system must do, not how it will be done. The analysis should not contain implementation decisions. The analysis model has two parts: 1. Domain model 2. Application model Domain model: A description of the real-world objects reflected within the system; Application model: A description of the parts of the application system itself that are visible to the user. 3. System design: The development team must plan a high level strategy-the system architecture-for solving the application problem. The system designer must decide what performance characteristics to optimize choose a strategy of attacking the problem, and make tentative resource allocations.

4. Class design: The class designer adds details to the analysis model in accordance with the system design strategy. The class designer should elaborate both domain and application objects using the OO concepts and notation, although they exist on different conceptual planes. 5. Implementation: Implementers translate the classes and relationships developed during class design into a particular programming language, database, or hardware. During implementation, it is important to follow good software engineering practice so that traceability to the design is apparent and so that the system remains flexible and extensible.

Explain the Three models


Three kinds of models are used to describe a system from different viewpoints Class model for the objects in the system and their relationships. State model for the life history of objects Interaction model for the interactions among objects

Class model: o It describes the static structure of the objects in a system and their relationships. o It defines the context for software development. o It Contains class diagrams. o Class diagrams are a graph whose nodes are the classes and whose arcs are relationships among classes. State model: o It describes the aspects of an object that change over time. o It specifies and implements control with state diagrams o State diagrams are a graph whose nodes are the states and whose arcs are transactions between states caused by events among classes. Interaction model: o It describes how the objects in a system cooperate to achieve broader results. o It starts with use cases that are then elaborated with sequence and activity diagram. Use Case diagrams focuses on functionality of a system-that is what the system does for the users. Sequence diagrams shows the objects that interact and the time sequence of their interactions. Activity diagrams elaborate important processing steps.

Explain OO Themes
Themes are not unique to OO systems, they are particularly well supported.

1. Abstraction
It focuses on essential aspects of an application while ignoring details. Focusing: on what an object is and does, before deciding how to implement it. Use--> Preserves (Keeps) the freedom to make decisions as long as possible by avoiding premature commitments to details. Modern languages provide data abstraction, but inheritance and polymorphism add power. Ability to abstract is the important skill required for OOdevelopment.

2. Encapsulation
It is also known as information hiding. It separates the external aspects of an object that are accessible to other objects, from the internal implementation details that are hidden from other objects. It is not unique to OO languages The ability to combine data structures and behavior in a single entity makes encapsulation cleaner and more powerful than prior languages 3. Combining Data and Behavior Maintenance is easier 4.Sharing OO techniques promote sharing at different levels. The sharing via inheritance is one of the main advantages of OO languages. OO development not only lets you share information within the application, but also offers the prospect of reusing designs code on future projects.

5. Emphasis on the essence of an Object


Oo development places a greater emphasis on data structure and a lesser emphasis on procedure structure than functional decomposition methodologies. Oo development is similar to information modeling techniques used in database design; Oo development adds the concept of class-dependent behavior.

6. Synergy
Identity, classification, polymorphism, and inheritance characterize Oo languages. Each of these concepts can be used in isolation, but together they complement each other synergistically. The Emphasis on the essential properties of an object forces the developer to think more carefully and deeply about what an object is and does.

usefulness of OO development
OO techniques are used for developing compilers, graphics, user interfaces, databases, an Oo language, CAD systems, simulations, metamodels, control systems, and other applications. Oo models are used to document programs that are ill-structured and difficult to understand.

Modeling as a design technique


What is an model? Model: It is an abstraction of something for the purpose of understanding it before building it. It is easier to manipulate than the original entity, because a model omits non-essential details.

Modeling
Designers build models for various purposes before constructing. Example: Architectural models to show customers, airplane scale models for wind tunnel tests, etc.., Models serve Several Purposes: Testing a physical entity before building it Communication with customers: Architects and product designers build models to show their customers. Visualization Reduction of complexity: The main reason for modeling, incorporates the previous reasons, is to deal with systems that are too complex to understand directly. Models reduce complexity by separating out a small number of important things to deal with at a time.

Explain Abstraction
Abstraction is a selective examination of certain aspects of a problem. The goal of abstraction is to isolate those aspects that are important for some purpose and suppress those aspects which are unimportant. Abstraction should always be for some purpose, because the purpose determines what is, and is not important. Abstractions are incomplete and inaccurate. The Three Models To model a system it is useful from three related but different viewpoints, each capturing important aspects of the system, required for a complete description. Class model represents the static, structural, data aspects of a system. State model represents the temporal, behavioral, control aspects of a system. Interaction model represents the collaboration of individual objects, the Interaction aspects of a system. Each model contains the references to entities in other models. For example: the class model attaches operations to classes, while state and interaction model elaborate the operations. The three kinds of models separate a system into distinct views. The different models are not completely independent. The different models have limited and explicit interconnections.

Class model
It describes the structure of objects in a system- their identity, their relationships to other objects, their attributes, and their operations. It provides context for the state and interaction models.

Goal of constructing a class model Is to capture those concepts from the real world that are important to an application. Class diagrams express the class model. Generalization lets classes share structure and behavior and associations relate the classes. Classes define attribute values carried by each object and the operations that each object performs or undergoes.

State model
It describes those aspects of objects concerned with time and the sequencing of operations It captures control, the aspect of a system that describes the sequences of operations that occur, without regard for what the operations do, what they operate on, or how they are implemented. State diagrams express the state model. Each state diagram shows the state and the event sequences permitted in a system for one class of objects. State diagram refers to other models. Actions and events in a state diagram become operations on objects in the class model. References between the state diagrams become interactions in the interaction model.

Interaction Model
It describes interactions between objects- how individual objects collaborate to achieve the behavior of the system as a whole. Use cases diagrams, sequence diagrams; activity diagrams document the interaction model. Use cases diagrams: documents themes for interaction between the system and outside actors. Sequence diagrams: shows the objects that interact and the time sequence of their interactions. Activity diagrams: show the flow of control among the processing steps of a computation.

Relationship Among the models

Class modeling
It captures the static structure of a system by characterizing the objects in a system. The relationship between the objects and the attributes and operations for each class of objects. Class model is important of three models. We should build a system around objects rather than functionality Because an Oo system is more closely corresponds to the real world and is more resilient with respect to change. Class models provide an intuitive graphical representation system and are valuable for communicating with customers.

Objects and class concepts


Define Objects

The purpose class modeling is to describe objects Example: Joe Smith, Simplex Company, Processno 7648, and top windows are objects. An object is a concept, abstraction, or thing with identity that has meaning for an application. Objects appear as proper nouns or specific references in problem descriptions and discussions with users. Some objects have real world counter parts while others are conceptual entities are introduced for implementation and have no correspondence to physical reality. The choice of objects depends on judgment and the nature of the problem. All objects have identity and are distinguishable. Example: Two apples with the same color, shape and texture are still appear individual apples, a person can eat one at a time. Identity: means that objects are distinguished by their inherent existence and not by descriptive properties that they may have.

Define Classes
An object is an instance or occurrence of a class. Class describes a group of object with the same properties (attributes), behavior (operation) kinds of relationships and semantics. Example: Person, Company, Process and Windows are all classes. Classes often appear as common nouns and nounpharses in problem descriptions. Objects in a class have the same attributes and forms of a behavior. Objects in a class share a common purpose above and beyond the requirements of common attribute and behavior. OO programming languages can determine an object class at run time. Class name and attribute name are stored one per class rather than one per instance.

Explain Class Diagrams and Object diagrams


Two kinds of models of structure are Class diagrams Object diagrams

Class diagrams: It provides a graphic notation for modeling classes and their relationship, thereby describing possible objects. It is useful for abstract modeling and for designing actual programs. They are concise, easy to understand and work well in practice. Singular nouns are used for the names of classes. Person Figure class diagram Object diagrams: It shows individual objects and their relationships. It is helpful for documenting test cases and discussing examples. A class diagram corresponds to an infinite set of object diagrams. JoeSmith:Person MarySharp:Person :Person Figure Object diagram Explain Values and Attributes A value is a piece of data. The values are found by examining problem documentation. An Attribute is a named property of a class that describes a value held by each object of the class. Object is to class value is to attribute. Attributes are less important and serve to elaborate classes and relationships. Example: Name, birth date and weight are attribute of person objects. Each attribute has a value for each object. Example birth date attribute has value 21 October 1983 for object Joe smith. Different objects have the same or different value for a given attribute. Attribute name is unique within a class. Attribute should describe values not objects. Values lack identity. Example country is an object whose name attribute has the value Canada (the string). Attribute elaborate classes Person
name: string birthdate: date

Figure: Class with attributes JoeSmith:Person


name= joe smith
birthdate=21 October 1983

MarySharp:Person
name= Mary Sharp
birthdate=16 march 1950

Figure: Objects with values

Explain Identifiers Are implicit in a class model. We need not and should not list them explicitly. Oo languages automatically generate identifiers with which to reference objects. Internal identifiers. Is purely an implementation convenience and have no application meaning.

Person personID: ID name: string birthdate: date homeTelephoneNumber: string

Person name: string birthdate: date homeTelephoneNumber:string

Wrong

Correct

Explain Operations and Methods An operation is a function or procedure that may be applied to or by objects in a class. Example: Hire, Fire and Pay dividend are operations on class company. All objects in a class shares same operation. Each operation has a target object as an implicit argument. Behavior of the operation depends on the class of its target. Same operations may be apply to many different classes Such operations are polymorphic. Method is an implementation of an operation for a class. Example: class file has the operation print An operation may have arguments in addition to its target object. When an operation has method on several classes, it is important that the methods all have the same signature.
Person name birthdate changeJob changeAddress File fileName sizeInBytes lastUpdate print GeometricObject color position move (delta : Vector) select (p : Point): Boolean rotate (in angle : float = 0.0)

Figure: operations

Notation for classes Class Name


attributeName1:dataType1=defaultValue1 attributeName2:dataType2=defaultValue2

OperationName1(argumentList1):resultType1 OperationName2(argumentList2):resultType2

Notation for an argument of an operation direction argument Name: type=default Value Explain Link and Association concepts
Links and associations are the means for establishing relationships among objects and classes. A Link is a physical or conceptual connection among objects. Example: Joe smith works for simplex company. Most links relate two objects, but some links relate three or more objects. A link is an instance of association. An association is a description of a group of links with common structure and common semantics. Example: A person works for a company. The Links of an association connect objects from the same classes. An association describes a set of potential links in the same way that a class describes a set of potential objects. Links and associations appear as verbs in problem statements
Class diagram
Person name John:Person name=John Mary:Person name=Mary GE:Company name=GE IBM:Company name=IBM OwnsStock

Company name

Object diagram

Sue:Person name=Sue Alice:Person name=Alice Jeff:Person name=Jeff

Figure: Many-to-Many association: An association describes a set of potential links in the same way that a class describes a set of potential objects.

Explain Multiplicity and cardinality Multiplicity is a constraint on the size of collection. Cardinality: is the count of elements that are actually in a collection. Therefore, Multiplicity is a constraint on the cardinality 0 or 1 multiplicity
Workstation
1 0..1 console

Window

Association Vs Link

anAssociation

anA:A

aLink

aB:B

Class diagram
Multiple association to model multiple links

Object diagram
anA:A aLink anotherLink aB:B

anAssociation * * B * anotherAssociation*

Class diagram

Object diagram

Explain Association end names It can give names to the association link The use of associations end name : to name links b/w object of some class

Person

employee

employer Company 0..1 WorksFor

employee employer Joe Doe Simplex Mary BrownSimplex Jean Smith United Widgets Association end names are necceaaary for associations between objects of the same class.
Parent

Child

Person
child

parent 0..2

Wrong model

Correct model

Explain Ordering, Bags and sequence Ordering: Association which follows some priority Eg. Windows opened on screen follow on explicit order only top most window is visible on any part of screen Ordered collection of elements with duplicates not allowed

Screen

{ordered} 1

VisibleOn

WIndow

Bags and sequences Bag: collection of elements with duplicates allowed Sequence: ordered collection of elements with duplicate allowed eg. An itinerary is a sequence of airports and the same airport can be visited more than once Sequence is ordered bag both allow duplicates, {ordered} and {sequence} is same only difference is sequence allows duplicates.
Itinerary
{sequence}

Airport

Explain Association Class It is an association that is also a class Link of association can have attributes

File

*
AccessibleBy accessPermission

User

/etc/termcap /etc/termcap /usr/doe/.login

read read-write read-write

John Doe Mary Brown John Doe

Attributes may occur for 1-m and 1-1 associations

Person
boss birthDate 0..1 address

*
WorksFor salary jobTitle

0..1

Company name address

name

Manages

worker

performanceRating
Proper use of association class

Person

*
WorksFor salary jobTitle

0..1

Company name address

Preferred form

name birthDate address

Person

WorksFor

0..1

Company name address

Discouraged form

name birthDate address salary jobTitle

An association class participating in an association

User

*
Authorization priority privileges startSession

* Workstation
homeDirectory Directory 1

Association class Vs. Ordinary class

Association class

Person name

OwnsStock quantity

Company name

Person

Ordinary class

name

Purchase quantity date cost

Company
1

name

Explained Qualified Associations An association in which an attribute called the qualifier disambiguates the objects for a many association end. Job of qualifier to reduce the many association to one. Can only work for m-m and 1-m

Bank accountNumber

0..1

Account

Bank

Account accountNumber

Qualified

Not qualified

Explain Generalization and inheritance Generalization is the relationship between a class (the super class) and one or more variations of the class (sub class). Super class holds the common attributes, operations and associations. Subclass adds specific attributes. Each subclass inherits features of super class
Equipment name manufacturer weight cost {Note: The listing of equipment, pumps, and tanks is incomplete.}

Pump suctionPressure dischargePressure flowRate

HeatExchanger surfaceArea tubeDiameter tubeLength tubePressure shellPressure

Tank volume pressure

CentrifugalPump impellerDiameter numberOfBlades axisOfRotation

DiaphragmPump diaphragmMaterial

PlungerPump plungerLength plungerDiameter numberOfCylinders

SphericalTank diameter

PressurizedTank diameter height E302:HeatExchanger name = E302 manufacturer = Brown weight = 5000 kg cost = $20000 surfaceArea = 300 m tubeDiameter = 2 cm tubeLength = 6 m tubePressure = 15 atm shellPressure = 1.7 atm

FloatingRoofTank diameter height T111:FloatingRoofTank name = T111 manufacturer = Simplex weight = 10000 kg cost = $50000 volume = 400000 liter pressure = 1.1 atm diameter = 8 m height = 9 m

P101:DiaphragmPump name = P101 manufacturer = Simplex weight = 100 kg cost = $5000 suctionPres = 1.1 atm dischargePres = 3.3 atm flowRate = 300 l/hr diaphragmMatl = Teflon

Use of generalization Support for polymorphism increases the flexibility of software. To structure the description of objects. To enable, reuse of code.

Figure
1

Diagram name

color centerPosition penThickness penType move select rotate display dimensionality

ZeroDimensional

OneDimensional orientation scale

TwoDimensional orientation fillType scale fill

Point

Line endPoints

Arc radius startAngle arcAngle display

Spline controlPts display

Polygon numOfSides vertices display

Circle diameter display rotate

display

display

Explain Class Model of windowing system


Window x1 y1 x2 y2 display undisplay raise lower

ScrollingWindow xOffset yOffset scroll cx1 cy1 cx2 cy2

Canvas

Panel itemName
1

addElement deleteElement
1 window 0..1 elements notifyEvent

Event action
1

Shape color lineWidth

*
keyboardEvent

PanelItem x y label

Text Window string insert delete

Scrolling Canvas

Line x1 y1 x2 y2 draw

Closed Shape fillColor fillPattern

Button string depressed

Choice Item
0..1 {subset} 1

TextItem maxLength currentString

currentChoice

Point x y

vertices

{ordered}

Polygon draw

Ellipse x y a b draw

ChoiceEntry string value

choices

Explain Navigation of class model Class model for managing credit card account
MailingAddress address phoneNumber
1

CreditCardAccount maximumCredit currentBalance statementDate


1 0..1 0..1 1

Institution accountNumber name address phoneNumber

* *
name
accountHolder

Customer

Statement paymentDueDate financeCharge minimumPayment transactionNumber

0..1

Transaction transactionDate explanation amount

CashAdvance

Interest

Purchase

Fee feeType

Adjustment

*
1

Merchant name

Object constraint language : It is Used to answer question pertaining to a class model Attribute syntax acreditcardaccount.maximumcredit Operations syntax by -> Simple association acustomer.mailingaddres Acreditcardaccount.mailingaddres How many credit card account customer has What transaction occurred in a time interval for a customer What transactions occurred for a credit card account within a time interval ? aCreditCardAccount.Statement.Transaction select(aStartDate <= transactionDate and transactiondate <= anEndDate The expression traverses from a CreditCardAccount object to Statement and then to Transaction, resulting in a set of transactions. (Traversal of the two associations results in a set, rather then a bag, because both associations are one-to-many.) Then we use the OCL select operator (a collection operator) to find the transactions within the time interval bounded by aStartDate and anEndDate What volume of transaction were handled by an institution in last year ? anInstitution. CreditCardAccount . Statement. Transaction-> select (aStartDate <= transactionDate and transactionDate <= anEndDate). Amount -> sum( )

The expression traverses from an institution object to CreditCardAccount, then to Statement, and then to transaction. (Traversal results in a set, rather then a bag, because all three associations are one-to-many.) The OCL select operator finds the transactions within the time interval bounded by aStartDate and anEndDate. (We choose to make the time interval more general than last year.) Then we find the amount for each transaction and compute the total with the OCL sum operator (a collection operator). What customers patronized a merchant in the last year by any kind of credit card ? aMerchant . Purchase-> Select (aStartDate <= transactionDate and TransactionDate <= anEndDate). Statement. CreditCardAccount . Mailingaddress. Customer->asSet() The expression traverses from a Merchant object to Purchase. The OCL select operator finds the transactions within the time interval bounded by aStartDate and anEndDate. (Traversal across a generalization, from Purchase to transaction, is implicit in the OCL.) for these transactions, we then traverse to Statement, then to CreditCardAccount, then to MailingAddress, and finally to Customer. The association from MailingAddress to customer is many-to-many, so traversal to Customer yields a bag. The OCL asSet operator converts a bag of customers to a set of customers, resulting in our answer. How many credit card accounts does a customer currently have ? aCustomer .Mailingaddress. CreditCardAccount-> size() Given a Customer object. We find a set of MailingAddress object. Then, given the set of MailingAddress objects, we find a set of CreditCardAccount object. (This traversal yields a set, and not a bag, because each creditCardAccount pertains to a single MailingAddress.) for the set of CreditCardAccount objects we apply the OCL size operator, which returns the cardinality of the set. What is the total maximum credit for as customer, for all accounts ? aCustomer. MailingAddress. CreditCardAccount. maximumCredit->sum () The expression traverses from a Customer object to MailingAddress, and then to CreditCardAccount, yielding a set of CreditCardAccount object. For each CreditCardAccount, we find the value of maximumCredit and compute the total with the OCLsum operator. Traversal of multiple association may yield a bag

Class diagram

MailingAddress address :Address address=123 Main :Address

Person name

OwnsStock

* name

Company

John:Person name=John Mary:Person name=Mary Sue:Person name=Sue GE:Company name=GE

Object diagram

address=456 State :Address address=789 First :Address address=234 Olive

Potrebbero piacerti anche