Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object Modeling (1) Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha

Similar presentations


Presentation on theme: "Object Modeling (1) Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha"— Presentation transcript:

1 Object Modeling (1) Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha (bhha@pusan.ac.kr)bhha@pusan.ac.kr

2 Lecture Outline  Introduction  Object and Classes  Links and Associations

3 Introduction  Object model  Static structure of a system by showing the objects in the system, relationships between the objects, and the attributes and operations that characterize each class of objects  Most important of the three models  Important concepts  Object, class, link, association, generalization, inheritance

4 Object and Classes  Objects  An object is simply something that makes sense in an application context e.g. Joe Smith, Simplex company, Lassie, process number 7648  Our definition A concept, abstraction, or thing with crisp boundaries and meaning for the problem at hand  Purposes Promote understanding of the real world Provide a practical basis for computer implementation  Decomposition of a problem into objects Depend on judgment and the nature of problem There is no one correct representation

5 Object and Classes  Classes  A group of objects with similar properties (attributes), common behavior (operations), common relationships to other objects, and common semantics  Objects in a class have the same attributes and behavior patterns share a common semantic purpose e.g. barn and horse with attributes of cost and age

6 Object and Classes  Classes (cont’)  We focus on object modeling, but why do we consider class? By grouping objects into classes, we abstract a problem! Common definitions and operations can be written once public class Vector { double x; double y; double length() { double len = Math.sqrt(x * x + y * y); return len; }

7 Object and Classes  Classes (cont’)  Each object “knows” its class Most object-oriented programming languages can determine an object’s class at runtime An object’s class is an implicit property of the object

8 Object and Classes  Each object “knows” its class  a.k.a. Run-Time Type Information (RTTI)  instanceof keyword in case of Java  But, someone doesn’t like RTTI public class Vector {... public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof Vector) { Vector v = (Vector)obj; return x == v.x && y == v.y; } return false; }

9 Object and Classes  Two types of object diagram  Class diagram Schema, pattern or template for describing many possible instances of data  Instance diagram How a particular set of objects relate to each other Useful for documenting test cases (especially scenarios) and discussing examples  A given class diagram corresponds to an infinite set of instance diagrams Person (Person) Joe Smith (Person) Mary Sharp (Person)

10 Object and Classes  Attribute  Data value held by the objects in a class  Should be a pure data value, not an object Pure data values do not have identity c.f. String object in case of Java  Each object has its own (internal) identity Do not confuse internal identity with real-world attributes e.g. SSN Person (Person) Joe Smith 24 (Person) Mary Sharp 52 name: string age: integer Person person ID: ID name: string age: integer Person name: string age: integer

11 Object and Classes  Operation  Function or transformation that may be applied to or by objects in a class  All object in a class share the same operations  Each operation has a target object as an implicit argument

12 Object and Classes  Operation (cont’)  Methods The same operation may apply to many different classes Such an operation is polymorphic Method is the implementation of an operation for a class  Queries Those that merely compute a function value without modifying any objects e.g. length() method of our Vector Base attribute vs. derived attributes The choice of base attributes is arbitrary but should be made to avoid over-specifying the state of object e.g. (x, y) vs. (ux, uy) & len in case of our Vector

13 Object and Classes  Operation (cont’) Person name age change-job change-address Geometric object color position move(delta: Vector) select(p: Point): Boolean rotate(angle)

14 Links and Associations  Link  A physical or conceptual connection between object instances  Association  A group of links with common structure and common semantics  Inherently bidirectional Country name City name Has-capital (Country) Canada (City) Ottawa Has-capital (Country) France (City) Paris Has-capital (Country) Senegal (City) Dakar Has-capital

15 Links and Associations  Association (cont’)  Associations are often implemented in programming language as “pointers” from one object to another e.g. “references” in case of Java PersonCompany Works-for public class Person { Company employer; } public class Company { Person employee; }

16 Links and Associations  Association (cont’)  Implementing associations as pointers is perfectly acceptable, but associations should not be modeled this way (why?) PersonCompany Works-for public class Person { Company employer; } public class Company { Person employee; } public static void main(String[] args) { Person p = new Person(); Company c = new Company(); p.employer = c; c.employee = p; }

17 Links and Associations  Example in CAD  Lines and points c.f. multiplicity symbols (solid balls and “2+”)  Sample data Could you draw an instance diagram for the sample data? Line name Point name Intersects 2+ L5 L3 L2 L4 L1 P1 P2

18 Links and Associations  Order of association  Binary, ternary, or higher order e.g. ternary association ProjectLanguage Person (Project) accounting (Language) Cobol (Person) Mary (Project) CAD (Language) C

19 Links and Associations  Order of association (cont’)  Q: same or not? ProjectLanguage Person ProjectLanguage Person

20 Homework  HW6: exercise 3.1 (p. 49)  HW7: write Java code of representing the instance diagram in Figure 3.7 (p. 29)


Download ppt "Object Modeling (1) Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha"

Similar presentations


Ads by Google