1 / 20

Object Modeling (1)

Object Modeling (1). Chapter 3 (1) Part 1: Modeling Concepts Object-Oriented Modeling and Design Byung-Hyun Ha ( bhha@pusan.ac.kr ). Lecture Outline. Introduction Object and Classes Links and Associations. Introduction. Object model

derora
Download Presentation

Object Modeling (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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)

  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 • publicclass Vector { • doublex; • doubley; • 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 • publicclass Vector { • ... • publicboolean equals(Object obj) { • if (this == obj) { • returntrue; • } • if (obj instanceof Vector) { • Vector v = (Vector)obj; • returnx == v.x && y == v.y; • } • returnfalse; • } • }

  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 person ID: ID name: string age: integer 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 Geometric object name age color position change-job change-address 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 Has-capital Country City name name (Country) Canada Has-capital (City) Ottawa (Country) France Has-capital (City) Paris (Country) Senegal Has-capital (City) Dakar

  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 Works-for Person Company • publicclass Person { • Company employer; • } • publicclass 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?) Works-for Person Company • publicclass Person { • Company employer; • } • publicclass Company { • Person employee; • } • publicstaticvoid 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? Intersects Line Point 2+ name name L1 L2 L3 L4 P1 P2 L5

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

  19. Links and Associations • Order of association (cont’) • Q: same or not? Project Language Person Project Language Person

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

More Related