Object-Oriented Analysis and Design

Similar documents
NOTES ON OBJECT-ORIENTED MODELING AND DESIGN

Class modelling (part 2)

ADVANCED LINK AND ASSOCIATION CONCEPTS

Class modelling (part 2)

Chapter 2: Entity-Relationship Model

Chapter No. 2 Class modeling CO:-Sketch Class,object models using fundamental relationships Contents 2.1 Object and Class Concepts (12M) Objects,

Database Design Process

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

Chapter 6: Entity-Relationship Model

Conceptual Data Models for Database Design

Entity Relationship Data Model. Slides by: Shree Jaswal

The OO Solution. Objects

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

Chapter 6: Entity-Relationship Model

Chapter 4. Enhanced Entity- Relationship Modeling. Enhanced-ER (EER) Model Concepts. Subclasses and Superclasses (1)

Object-Oriented Analysis and Design

Chapter (4) Enhanced Entity-Relationship and Object Modeling

The Entity-Relationship (ER) Model 2

Database Design Process. Requirements Collection & Analysis

OVERVIEW OF DATABASE DEVELOPMENT

CMPT 354 Database Systems I

Prepared By:Mitali sonar


SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

Database Applications (15-415)

MIS Database Systems Entity-Relationship Model.

Modeling Databases Using UML

The Entity-Relationship Model. Steps in Database Design

Entity-Relationship Model

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Chapter 7: Entity-Relationship Model

What are the characteristics of Object Oriented programming language?

Chapter 7: Entity-Relationship Model

Database Design Phases. History. Entity-relationship model. ER model basics 9/25/11. Entity-relationship (ER) model. ER model basics II

Object-Oriented Systems Development: Using the Unified Modeling Language

E-R Model. Hi! Here in this lecture we are going to discuss about the E-R Model.

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Enhanced Entity-Relationship (EER) Modeling

COIS Databases

Chapter 7: Entity-Relationship Model

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Design Pattern: Composite

Entity-Relationship Modelling. Entities Attributes Relationships Mapping Cardinality Keys Reduction of an E-R Diagram to Tables

Relationships Between Real Things. CSE 143 Java. Common Relationship Patterns. Composition: "has a" CSE143 Sp Student.

Chapter 1 Chapter-1

CMP-3440 Database Systems

Sommerville Chapter 7 Fowler Chapters 1, 3, 5, and 6. Conceptual Modeling and Class Diagrams

Chapter 5: Structural Modeling

COMP Instructor: Dimitris Papadias WWW page:

BBM 102 Introduction to Programming II Spring Inheritance

Chapter 2 ENTITY RELATIONSHIP MODEL

Relationships Between Real Things CSE 143. Common Relationship Patterns. Employee. Supervisor

Introduction to Software Engineering. 5. Modeling Objects and Classes

Chapter 3 Database Modeling and Design II. Database Modeling

Data Modeling Using the Entity-Relationship Model

Suggested answers are provided below. These answers are presented top-down, left to right.

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

CS111: PROGRAMMING LANGUAGE II

Lecture 7, Part 1: Object Oriented Modelling

Relationships Between Real Things CSC 143. Common Relationship Patterns. Composition: "has a" CSC Employee. Supervisor

Object-Oriented Software Engineering Practical Software Development using UML and Java

CS111: PROGRAMMING LANGUAGE II

REVIEW OF THE BASIC CHARACTERISTICS OF OBJECT ORIENTATION

Object-Oriented Introduction

Overview of Database Design Process Example Database Application (COMPANY) ER Model Concepts

Chapter 11 Object and Object- Relational Databases

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

CSE 530A. ER Model. Washington University Fall 2013

Data Modeling Using the Entity-Relationship (ER) Model

2004 John Mylopoulos. The Entity-Relationship Model John Mylopoulos. The Entity-Relationship Model John Mylopoulos

Database Management Systems. Chapter 2 Part 2

Chapter 10. Object-Oriented Analysis and Modeling Using the UML. McGraw-Hill/Irwin

ER modeling. Lecture 4

Unit I. By Prof.Sushila Aghav MIT

Chapter 8: Enhanced ER Model

Weak Entity Sets. A weak entity is an entity that cannot exist in a database unless another type of entity also exists in that database.

Essentials of Database Management (Hoffer et al.) Chapter 2 Modeling Data in the Organization

Enhanced Entity- Relationship Models (EER)

Chapter 2: Entity-Relationship Model. Entity Sets. Entity Sets customer and loan. Attributes. Relationship Sets. A database can be modeled as:

CSIT5300: Advanced Database Systems

Relational Data Model

CH3. Class Modeling Tae-Hoon Song. Michael Blaha, James Rumbaugh Object-Oriented Modeling and Design with UML SE LAB KAIST

Object-Oriented Data Modeling. After studying this chapter, you should be able to:

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Programming in C# Inheritance and Polymorphism

Chapter 2. Database Design. Database Systems p. 25/540

Chapter 7: Entity-Relationship Model

SOFTWARE DESIGN COSC 4353 / Dr. Raj Singh

Multiple Choice Questions

LAB 2 Notes. Conceptual Design ER. Logical DB Design (relational) Schema Refinement. Physical DD

Chapter 17. Methodology Logical Database Design for the Relational Model

Chapter 6: Entity-Relationship Model

Conceptual Database Design. COSC 304 Introduction to Database Systems. Entity-Relationship Modeling. Entity-Relationship Modeling

Self-review Questions

Äriprotsesside modelleerimine ja automatiseerimine Loeng 7 Valdkonna mudel

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

LELCTURE 4: ENHANCED ENTITY-RELATIONSHIP MODELING (EER)

Transcription:

Object-Oriented Analysis and Design 4 ADVANCED OBJECT MODELING Source: OBJECT-ORIENTED MODELING AND DESIGN James Rumbaugh, Michael Blaha, William Premerlani, Frederick Eddy, William Lorensen PAUL VOUGNY - EPITA 2008

1. AGGREGATION Aggregation is a strong form of association in which an aggregate object is made of components. Components are part of the aggregate. Aggregation is inherently transitive; an aggregate has parts, which may in turn have parts. Recursive aggregation is common.

AGGREGATION versus ASSOCIATION Aggregation is a special form of association, not an independent concept. Aggregation adds semantic connotations in certain cases. If two objects are tightly bound by a part-whole relationship, it is an aggregation. If the two objects are usually considered as independent, even though they may often be linked, it is an aggregation. Some tests include: Would you use the phrase part of? Are some operations on the whole automatically applied to its parts? Are some attributes values propagated from the whole to all or some parts? Is there an intrinsic asymmetry to the association, where one object class is subordinate to the other?

Company Division Department Works for Person Aggregation and association

AGGREGATION versus GENERALIZATION Aggregation is not the same thing as generalization. Aggregation relates instances. Two distinct objects are involved; one of them is a part of the other. Generalization relates classes and is a way of structuring the description of a single object. Both superclass and subclass refer to properties of a single object. With generalization, an object is simultaneously an instance of the superclass and an instance of the subclass. Aggregation is often called a-part-of relationship; Generalization is often called a-kind-of or is-a relationship.

Lamp Fluorescent Lamp Incendescent Lamp Base Cover Switch Wiring Ballast Twist mount Starter Socket Aggregation is sometimes called an and-relationship and generalization an or-relationship. Aggregation and generalization A lamp is made of a base and a cover and a switch and wiring and so on. A lamp is a fluorescent lamp or an incandescent lamp.

RECURSIVE AGGREGATES Aggregation can be fixed, variable, or recursive. A variable aggregate has a finite number of levels, but the number of parts may vary. A recursive aggregate contains, directly or indirectly, an instance of the same kind of aggregate; the number of potential levels is unlimited. Program Recursive Aggregate Block Compound statement Simple statement

PROPAGATION OF OPERATIONS Propagation (also called triggering) is the automatic application of an operation to a network of objects when the operation is applied to some starting object. For example, moving an aggregate moves its parts; the move operation propagates to the parts. Propagation of operations to parts is often a good indicator of aggregation. Person Owns Document copy Paragraph copy Character copy copy copy Propagation of operations Most of the approaches present an all-or-nothing option: copy an entire network with deep copy, or copy the starting object and none of the related objects with shallow copy. The propagation behavior is bound to an association (or aggregation), direction, and operation. The arrow indicates the direction of propagation.

2. ABSTRACT CLASSES - An abstract class is a class that has no direct instances but whose descendent classes have direct instances. - A concrete class is a class that is instantiable; that is, it can have direct instances. - A concrete class may have abstract subclasses (but they in turn must have concrete descendants). - A concrete class may be a leaf class in the inheritance tree; only concrete classes may be leaf classes in the inheritance tree. subclass subclass Class 1+ 1+ Has subclasses Object model Has subclasses defining abstract and concrete class Instance Has direct instances Concrete class Abstract class superclass superclass Non-leaf concrete class Leaf class The figure summarizes the definition of abstract and concrete class.

All the occupations shown here are concrete classes Class is an exemple of abstract class. All employees must be either hourly, salaried, or exempt. Worker Abstract class and abstract operation Butcher Baker Candlestick Maker... year-to-date earnings compute pay {abstract} Concrete classes Hourly hourly rate overtime rate compute pay Salaried weekly rate compute pay Exempt monthly rate compute pay

Abstract classes organize features common to several classes. It is often useful to create an abstract superclass to encapsulate classes that participate in the same association or aggregation. Abstract classes are frequently used to define methods to be inherited by subclasses. On the other hand, an abstract can define the protocol for an operation without supplying a corresponding method. We call this an abstract operation. A method is the actual implementation of an operation. An abstract operation defines the form of an operation for which each concrete subclass must provide its own implentation. A concrete class may not constain abstract operations because objects of the concrete class would have undefined opererations. The origin class defines the protocol of the feature, that is the type of an attribute or the number and type of arguments and result type for operations, as well as the semantic intent. Descendent classes can refine the protocol by further restricting the types or by overriding the initialization or method code. Descendent classes may not expand or change the protocol. A concrete class can usually be refined into several subclasses, making it abstract. Conversely, an abstract class may become concrete in an application in which the difference among its subclasses is unimportant.

3. GENERALIZATION AS EXTENSION AND RESTRICTION An instance of a class is an instance of all ancestors of the class. This is part of the definition of generalization. Therefore all ancestor class features must apply to the subclass instances. A descendent class cannot omit or suppress an ancestor attribute because then it would not truly be an ancestor instance. Similary operations on an ancestor class must apply to all descendent classes. A subclass may reimplement an operation for reasons of efficiency but cannot change the external protocol. A subclass may add new features. This called extension. A subclass may also constrain ancestor attributes. This is called restriction because it restricts the values that instances can assume.

For example, a circle is an ellipse whose major and minor axes are equal. Arbitrary changes to the attribute values of a restricted subclass may cause it to violate the constraints, such that the result no longer belongs to the orignal subclass. This is not a problem for the perspective of the superclass because the result is still a valid superclass instance. For example, a circle that is scaled unequally in the x and y dimensions remains an ellipse but is no longer a circle. Class Ellipse is closed under the scaling operation, but Circle is not. Inherited features can be renamed in a restriction. Restriction implies that a subclass may not inherit all the operations of its ancestors. Thus, the Circle class must suppress the unequal scale operation. On the other hand, an object declared to be an ellipse is not restricted to remain a circle even if its major and minor axes happen to be temporarily equal. x y x

OVERRIDING OPERATIONS Overriding for extension The new operation is the same as the inherited operation, except it adds some behavior, usually affecting new attributes of the subclass. Overriding for restriction The new operation restricts the protocol, such as tightening the types of arguments. Overriding for optimization The new method must have the same external protocol and results as the old one, but its internal representation and algorithm may differ completely. Overriding for convenience The new class is made a subclass of existing class and overrides the methods that are inconvenient.

We propose the following semantic rules for inheritance. Adherence to these rules will make a software easier to understand, easier to extend, and less prone to errors of oversight: All query operations (operations that read, but do not change, attribute values) are inherited by all subclasses. All update operations (operations that change attributes values) are inherited across all extensions. Update operations that change constrained attributes or associations are blocked across a restriction. For example, the scale_x operation is permitted for class Ellipse, must be blocked for subclass Circle. Operations may not be overridden to make them behave differently (in their externally-visible manifestations) from inherited operations. All methods that implement an operation must have the same protocol. Inherited operations can be refined by adding additional behavior.

4. MULTIPLE INHERITANCE Multiple inheritance permits a class to have more than one superclass and to inherit features from all parents. This permits mixing of information from two or more sources. It brings object modeling closer to the way people think. The disadvantage is a loss of conceptual and implementation simplicity. DEFINITION A class with more than one superclass is called a join class. Conflict among parallel definitions create ambiguities that must be resolved in implementations. In practise, such conflicts should be avoided or explicitly resolved to avoid ambiguities or misunderstandings, even if a particular language provides a priority rule for resolving conflicts.

Vehicle LandVehicle WaterVehicle overlapping subclasses Multiple inheritance from overlapping classes Car AmphibiousVehicle Boat disjoint subclasses join class The generalization subclasses may or may not be disjoint. For example, LandVehicle and WaterVehicle overlap because some vehicles travel on both land and water. A hollow triangle indicates disjoint subclasses; a solid triangle indicates overlapping subclasses.

pay status pension status Hourly Salaried Exempt Vested Unvested disjoint subclasses Vested Hourly join class Multiple inheritance from disjoint classes Hourly, Salaried, and Exempt are disjoint; each employee must belong to exactly one of these. A class can multiply inherit from distinct generalization or from different classes within an overlapping generalization but never from two classes in the same disjoint generalization. - generalization: conceptual relationship - inheritance: language mechanism

ACCIDENTAL MULTIPLE INHERITANCE An instance of a join class is inherently an instance of all the ancestors of the join class. For example, an instructor is inherently both faculty and student. But what about a Harvard Professor taking classes at MIT? This an example of "accidental" multiple inheritance, in which one instance happens to participate in two overlapping classes. Person University Member Workaround for accidental multiple inheritance Faculty Student Staff Instructor

WORKAROUNDS Dealing with lack of multiple inheritance is really an implentation issue, but early restructuring of model is often the easiest way to work around its absence. Delegation is an implentation mechanism by which an object forwards an operation to another object for execution. Delegation using aggregation of roles A superclass with multiple independent generalizations can be recast as an aggregate in which each component replaces a generalization. Inherit the most important class and delegate the rest The join class is treated as an aggregation of the remaining superclass and their operations are delegated as in the previous alternative. Nested generalization Factor on one generalization first, then the other. This approach multiplies out all possible combinations. This preserves inheritance but duplicates declarations and code and violates the spirit of object-oriented programming.

pay status Payroll Pension pension status Hourly Salaried Exempt Vested Unvested Multiple inheritance using delegation figure 1

pay status Pension pension status Hourly Salaried Exempt Vested Unvested Multiple inheritance using inheritance and delegation figure 2

pay status Hourly pension status Salaried pension status Exempt pension status Hourly Vested Hourly Unvested Salaried Vested Salaried Unvested Exempt Vested Exempt Unvested Multiple inheritance using nested generalization figure 3

Any of these workarounds can be made to work, but all compromise logical structure and maintainability. Some issues to consider when selecting the best workaround are: If a subclass has several superclasses, all of equal importance, it may be best to use delegation (figure 1) and preserve symmetry in the model. If one superclass clearly dominates and the others are less important, implementing multiple inheritance via single inheritance and delegation may be best (figure 2). If the number of combinations is small, consider nested generalization (figure 3). If the number of combination is large, avoid it. If one superclass has significantly more features than the other superclasses or one superclass clearly is the performance bottleneck, preserve inheritance through this path (figure 2 or figure 3). If you choose to use nested generalization (figure 3), factor on the most important criterion first, the next most important second, and so forth. Try to avoid nested generalization (figure 3) if large quantities of code must be duplicated. Consider the importance of maintaining strict identity. Only nested generalization (figure 3) preserves this.

5. METADATA Metadata is data that describes other data. For example, the definition of a class is metadata. Models are inherently metadata, since they describe the things being modeled (rather than being the things). Thus a data table may store the fact that the capital of Japan is Tokyo. A metatable would store the fact that a country has a capital city. PATTERNS AND METADATA A class describes a set of object instances of a given form. Instantiation relates a class to its instances. In a broader sense, any pattern describes examples of the pattern; the relationship between pattern and example can be regarded as an extension of instantiation. Person name age weight (Person) Joe Smith age = 39 weight = 158 (Person) Mary Wilson age = 27 weight = 121 Notation for instantiation

Real-world things may be metadata. pattern object It is better to consider the CarModel object as a pattern, a piece of metadata, that describe Car objects. CarModel model year base price Manufacturer Car serial # color options Owner Pattern and individuals Company Person

CLASS DESCRIPTORS Classes can also be considered as objects, but they are meta-objects and not realworld objects. Class descriptor objects have features, and they in turn have their own classes, which are called metaclasses. A class attribute describes a value common to an entire class of objects, rather than data peculiar to each instance. Class attributes are useful for storing default information for creating new objects or summary information about instances of the class. A class operation is an operation on the class itself. The most common kind of class operations are operations to create new class instances. Operations to creates instances must be class operations because the instance being operated on does not initially exist. A query that provides summary information for instances in a class is also a class operation. Operations on class structure, such as scanning the list of attributes or methods, are class operations. Window size : Rectangle visibility : Boolean $all_windows : set[window] $visible_windows : set[window] $default_size : Rectangle $maximum_size : Rectangle display $new_window $get_highest_priority_window Class with class features

6. CANDIDATE KEYS The best approach for n-ary associations is to specify candidate keys. A candidate key is a minimal set of attributes that uniquely identifies an object or link. It means that we cannot discard an attribute from the candidate key and still distinguish all object and liniks. A class or association may have one or more candidate keys, each of which may have different combinations and numbers of attributes. The object ID is always a candidate key for a class. One or more combinations of related objects are candidate keys for associations. Each candidate key constrains the instances in a class or the multiplicity of an association. Multiplicity and candidate keys have nearly the same expressive power for binary associations.

Many-to-many association One-to-many association Optional-to-one association Person Person Country Owns_stock Works_for Has_capital Company Company City {Candidate key: (person, company)} {Candidate key: (person)} {Candidate keys: (country) (city)} Comparison of multiplicity with candidate keys for binary associations

Project Language Person Ternary associations {Candidate key: (project, person, language)} Project CAD program control software C++ compiler CAD program CAD program CAD program Person Mary Susan Mike Bob Mike Mike Language C Ada C assembler C assembler We deduce the candidate key by considering all the possibilities.

Student University Professor Ternary associations {Candidate key: (student, university)} Student Mary Mary Susan Susan Bob Professor Prof Weaver Prof Rumrow Prof Weaver Prof Weaver Prof Shapiro University SUNY RPI RPI SUNY Oxford Student+University may be a candidate key, since no links share the same values. Student+Professor+University is not a candidate key, because it is not a minimal set of attributes.

7. CONSTRAINTS DEFINITION Constraints are functional relationship between entities of an object model. The term entity includes objects, classes, attributes, links, and associations. A constraint restricts the values that entities can assume. Examples include: - a constraint between two things at the same time; - a constraint between properties of a single object; - constraint on the same object over time. Constraints on objects Simple constraints may be placed in object model. Complex constraints should be specified in the functional model. salary boss Window length width Job priority {salary boss.salary} {0.8 length/width 1.5} {priority never increases}

CONSTRAINTS ON LINKS Multiplicity constraints an association. It restrict the number of objects related to a given object. The notation "{ordered}" indicates that the elements of the "many" end of an association have an explicit order that must be preserved. {ordered} Country Office Person Constraints on association links GENERAL CONSTRAINTS Subset constraint between associations Person Member_of {subset} Chair_of Committee

DERIVED OBJECTS, LINKS, AND ATTRIBUTES A derived object is defined as a function of one or more objects, which in turn may be derived. The derived object is completely determined by the other objects. Similarly, there are also derived links and derived attributes. The derived value notation is optional. Person birthdate /age Current date {age = currentdate - birthdate} Derived attribute Machine Assembly Part Derived object and association offset offset NetOffset {offset = assembly_machine.offset part_assembly.offset} Offset It is important to distinguish independent and dependent entities in a model. Derived entities are constrained by their base entities and the derivation rule.

HOMOMORPHISMS A homomorphism maps between two associations. Homomorphism for a parts catalog mapping Contains Maps Contains CatalogItem model number Describes Item serial number {item1 contains item2 item1.model contains item2.model}

In general, a homomorphism involves four relationships among four classes as shown on the figure below. mapping A r B t {u(b,d) t(b.r, d.s)} u General homomorphism C s D Homomorphisms are most likely to occur for complex applications that deal with metadata. The homomorphism is essentially just an analogy: a special type of relationship between relationships.