Sie sind auf Seite 1von 50

Object Model

Object Model
Based on a perception that a real world consists of a set of basic objects, called Objects and Relationships among these objects.

Collection of objects Relationships among objects

Structure Diagram

Object
 

Object is anything that has space and shows behaviour ObjectObject- Thing which has existence distinguishable from other objects (things)  independent existence  concrete or abstract described by its space and behaviour  has its own identity

Example Rama, Raghu Two glasses

Exercise

Can you consider the following as objects MRCE

The colour red

Abstraction
Look at only that snapshot of the world that is of interest Employee Rama: Name, salary Hire, Retire Project Robot: start date, end date Calc. expenditure, find status not name of grandfather

not number of workers

Abstraction: identify the common properties across things Rama and Raghu are employees Robot and Moon mission are projects common Name, salary start, end date are common

Structuring Abstraction
Most basic structuring mechanism is Classification Class C = {x|x satisfies P} where P is a predicate Normally, P is a statement in the propositional logic

Example Employee = (person|person satisfies is employee} Male Employee = {person|person is male and is employee}

Classification groups elements having common properties

Object Class


An object class is a class of objects of the same type; objects that share the same properties. Object class : Employee, Project, Department Sets are not necessarily disjoint Sets : Male Employee and Married Employee Can be a subset Sets : Person and Feminine Person
Employee

A Relationship


A relationship is an association among several objects objects

Example Rama owns Ekta Bhawan Raghu owns Ashiana Dravid plays cricket Pillai plays hockey TV model 3344 is available in the Sony showroom at Solan

relationship

A Relationship Class/Association Class




An association class is a class of relationships of the same type, having common properties

Let E1, E2, ... En be entity sets and E1, E2, ... En participate in association A A E1 x E2 x ... x En = {<e1, e2, ..., en> ei Ei } <e1, e2, ..., en> is an association, A is the association set Example The degree of the association: n Owns(Person, House) owns Plays(Person, game) House Person Available(TV, Shop, City)

Roles

Objects participating in an association act certain parts in it.

Role is the function performed by the object in the association. Example Owns(Person, House) Plays(Person, game) Available(TV, Shop, City)
owns Person owner owned House

Owner, Owned Player, Played Object, Source, Location

Exercise
Define associations for the following situations Students register for courses Students register for courses taught by different teachers A timetable is made for a course taught by a teacher in a classroom during a given period

Cardinality/Multiplicity

Expresses the 1:1, 1:N, M:N constraint on the relation defining the association Answers the question How many Example Owns(Person, House) Plays(Person, game) Available(TV, Shop, City)
1 Person owner owned owns

How many? How many? How many?


3 House

1:N 1:1 1:N:M

Attributes


Descriptive Property

Takes values from a permitted set - Domain or value set Information about an object or association can be expressed by a set of (attribute, value) pairs

Person with attributes name, age { (name, Hari); (age, 20) } Works_for : attributes name, project, percent_of_time { (name, Raghu); (project, Insurance); (Percent_of_time, 30) }

Attributes


An attribute is a function from one object set or association set into a value set or a cartesian product of value set  simple attribute Ai : O or A -----> Vi name : Person ---> string  composite attribute Ai : O or A -----> Vi1 X Vi2 X..Vin streetno street streetname

address

city pincode

Attributes
Single vs Multivalued


Single valued - one value for an object/association (name, Hari) Hari)


Person name doB telNo

Multivalued - a set of values for an object/association (tel-number, 239201 and 245361) Base vs. Derived attribute
 

Base - value directly available Derived - value derived through other attributes/computation Base: Individual marks, Derived: Overall grade Base: date-of-birth, Derived: age date-of-

Attributes of Association Classes

Owns share

1 Person owner

3 House owned

Exercise
Define attributes for the following relationships Students register for courses A timetable is made for a course taught by a teacher in a classroom during a given period Nehru was the Prime Minister, Minister of Science, and Congress President

Operations
An operation is an abstraction of what objects can do, services they provide.

Employee name doB telNo

employee() hire() promote() retire()

Organizing/Descriptions
Employee name doB telNo <<Constr>> employee() stereotype <<actions>> hire() promote() retire() <<actions>> hire() promote() retire() Responsibilities -- handle HR activity stereotype Employee name doB telNo <<Constr>> employee()

Exercise
Model the following situations and represent them as structure diagrams Students register for courses A timetable is made for a course taught by a teacher in a classroom during a given period Nehru was the Prime Minister, Minister of Science, and Congress President

Exercise
A wholesale vegetable market sells different kinds of fruit and vegetables at different prices. Fruit is sold in units of a box whereas vegetables are sold in units of 5kg. Corporate/regular customers are offered a 10% discount on the price whereas others can negotiate the price up to a discount of 5%. A corporate/regular customer is one who buys at least Rs.1000/- worth in at least two lots per month. Fruit, Vegetable, list price, unit, discount, irregular customer, corporate customer, negotiated discount sale price? : can calculate or can store unit of produce? Sale? of a product at a price to a customer in some quantity Corporate customer definition as a constraint on customer

Solution
Fruit Name Rate Buys Discount Buyer Name Type Purchase_ history Classify() Veg Name Rate Buys Discount

Modeling Exercise
A timetable is made for a course taught by a teacher in a classroom during a given time period. There are different kinds of courses, subject elective, open elective, core, audit. For elective courses, the time period of the course is decided by the teacher of the course. Draw a structure diagram for building time tables How to represent associations that have a degree greater than 2 How to represent different kinds of courses

Abstraction Revisited

Classification: Flat Abstraction


Classification is the simplest structure for dealing with abstraction C = {x/ x satisfies P} A collection of objects is considered as a high level object class. An object is an instance of a class if it has the properties defined in the class. An object class is a precise characterization of the properties shared by each object in the collection. Classification is used to identify, classify, and describe objects.

Classification represents an is member-of relationship between the class and its members

Abstraction Hierarchies
When there are too many details, we may want to view these properties in a hierarchy of abstractions most general at the root most specific at the leaves

Abstraction provides a structuring discipline Identify universally applicable interesting properties Determine those special properties applicable to different subsets Apply recursively to each subset till properties are exhausted

Break a main class into subordinate classes and arrange them hierarchically

Aggregation
Produces objects that are in a hierarchical relationship with one another Transforms a relationship between several named objects into a higherlevel named object Relationship Reserves associate Objects person, room, duration building, street, city Aggregate reservation address

An aggregation represents is part of relationship between objects Person is part of reservation Duration is part of reservation Building is part of address

Aggregation
Want to express relationship with a relationship
Booking Person Book Flight

Ticket Ticket

Aggregation
Provides meaning to a relationship Student P received grade G in a class of the course C# with CH credit hours and description D taught by instructor I during semester S in room R

G P

C#

What is the meaning of Rel?

CH

Rel

Aggregation
Performance

Class

Course

C#

CH

Aggregation/Complex Object Classes


An aggregate class T built over object classesT1, T2, , Tn is the Cartesian product of these components T = T1 X T2 X, .., Tn

Object classes: Building, Street, City Aggregate class: Address Address = Building X Street X City 1 Address has 1 Building part 1.. * member 1 City 1.. *

Instances of the aggregate class are called aggregate objects/complex objects

1 street

Exercise
A passenger train is put together in a railway yard. It must have an engine and a number of bogies of different classes: Chair car, First class, and Second class. Each bogey has a determined number of people to seat and sleep. It has a number that identifies it. Every bogie has a conductor. Each train class has its own ticket checker. A given engine can be attached or detached from a train. Similarly, bogies can be attached or detached to a train. Draw a structure diagram. Write an O-O program to implement this structure.

Solution: attributes not shown


Train

Engine

First

Second

Number

Ticket checkes

Exercise
At the time of admission a student is allowed to register for a degree programme. Each degree is identified by a title and has a determined number of credits for its award. Associated with each programme is a Head of Department who has a name, an employee number, and a rank. Once a student is registered, he/she is given a place in the hostel. Information about the hostel number and hostel room number is to be maintained. Draw a structure diagram. Define operations for each class and develop an OO program

Generalisation/Specialisation
An abstraction that allows a class to be treated as a high level single named object class, called generic object class Generalisation: Relationship between a more general class and a specific kind of that class.

Employee Is-A Faculty Related?

Employee Is-A Staff

Yes, by the common property of being Employees

Generic Hierarchies
Document Root generic object

Periodical

Fixed

lower level generic objects

Journal

Magazine

Book

Manual

An individual which is a book is a member of each of the classes, Book, Fixed, and Document

Generic Hierarchies
A generic hierarchy can have a generic object which is an immediate descendent of one or more generic objects

Output Unit

Input Unit Multiple Is-A links Disk

Winchester

CD

Inheritance
Inheritance : Properties of the generic object are inherited downwards

A lower-level object inherits all the attributes, relationships, operations lower-

Balance Account

Belongs Customer

Savings

Current

Generic Hierarchies
A higher level generic object is referred to as a super class Its direct lower level object is called its sub class Properties Sub setting: The set of members of a subclass is a subset of the set of members of super-class Inheritance: The set of properties of a subclass is a superset of the set of properties of its superclass

Exercise
A passenger train is put together in a railway yard. It must have an engine and a number of bogies of different classes: Chair car, First class, and Second class. Each bogey has a number that identifies it. A first class bogey can sleep 48 persons and can seat 1.5 times as many; a second class bogey can sleep and seat 75 persons whereas a chair car can seat 53 persons. Identify and draw a generalisation hierarchy.

Constraints on Hierarchies
Participation: between generic objects across hierarchy levels Mandatory: all members of super-class are mapped to one or other subclass {Super} = {Sub1} U {Sub2}U ..{Subn} Optional: some members of super class are unmapped {Super} {Sub1} U {Sub2}U ..{Subn}

Disjointness: between generic objects at a given level Partitioned: Two subclasses are mutually disjoint {Sub1} + {Sub2} = null Overlapping: Two subclasses are not mutually disjoint

Exercise
What are the participation and disjointness constraints in the hierarchy

Doctor

Physician

Surgeon

Cardiologist

Orthopaedist

Neuro

Opthalmic

Others

Constraints on Hierarchies
Strictness: what is inherited Strong inheritance: all the properties of the super class are inherited by the sub class Weak/Loose inheritance: only a subset of the properties are inherited

Exercise
A passenger train is put together in a railway yard. It must have an engine and a number of bogies of different classes: Chair car, First class, and Second class. Each bogey has a number that identifies it. A first class bogey can sleep 48 persons and can seat 1.5 times as many; a second class bogey can sleep and seat 75 persons whereas a chair car can seat 53 persons. In the hierarchy for this problem drawn earlier, identify all constraints.

Attributes of Generic Objects


Attributes: information known to hold over all members of the class that is generalised Generic object Man Person Attributes Biped, Erect posture Name, DOB

Attributes may carry special information of no relevance to class being generalised Generic object Employee Attributes Max-salary, Avg-salary MaxAvg-

Generic Objects in Relationships


Relationships may be among selected types of the hierarchy Relationships among all types of the hierarchy Faculty borrow journals

more precise model Borrows is a constraint : update check

borrow
Faculty Document

restrict to subset Journals, retrieval optimisation

borrows

Periodical

Fixed

Journal

Magazine

Book

Manual

Dependency


A change in one thing may affect another.


The most common dependency between two classes is one where one class <<use>>s another as a parameter to an operation.
AudioClip name record(m:Microphone) start() stop() CourseSchedule addCourse(c : Course) removeCourse(c : Course Course Microphone

dependency Using relationship

Usually initial class diagrams will not have any significant number of dependencies in the beginning of analysis but will as more details are identified.

Dependency
AbstractClass {abstract} attribut e concreteOperation() abstractOperation() generalization ClassName

Among Classes
<<interface>> InterfaceName operation() <<instanceOf>> realization

<<metaclass>> MetaClassName

-simpleAttribute: Type = Default #classAttribute: Type +/derivedAttribute: Type +operation(in arg: Type = Default): ReturnType <<instanceOf>> objectName: ClassName Attribute = value simpleAttribute: Type = Default classAttribute: Type /derivedAttribute: Type

<<use>>

ClientClass

Dependency Among Classes




Eight Stereotypes of Dependency Among Classes


       

bind:
parameters

the source instantiates the target template using the given actual

derive: the source may be computed from the target friend: the source is given special visibility into the target instanceOf : the source object is an instance of the target classifier instantiate: the source creates instances of the target powertype: powertype: the target is a powertype of the source; a powertype is a
classifier whose objects are all the children of a given parent

refine: the source is at a finer degree of abstraction than the target use: the semantics of the source element depends on the semantics of the
public part of the target

Dependency Among Use Cases




Two Stereotypes of Dependency Among Use Cases: Cases:  extend: the target use case extends the behavior of the source extend:  include: the source use case explicitly incorporates the behavior of another include:
use case at a location specified by the source
System Use Case A

Actor
<<actor> > Actor

<<include>><<extend>> Use Case B Use Case C

Order Processing System Place Order Extension points 1 *


Additional requests: after creation of the order <<extend>> Request Catalog The sales person asks for the catalog

SalesPerson

<<include>><<include>>

<<include>>

Supply Customer Info. Order Item Make Payment

Das könnte Ihnen auch gefallen