Docsity

Object-Oriented Design - Software Architecture and Design | CS 6310, Papers of Computer Science

Partial preview of the text

Download Object-Oriented Design - Software Architecture and Design | CS 6310 and more Papers Computer Science in PDF only on Docsity!

Object-oriented Design

1. From analysis to design

2. System design

3. Object design

4. Abstraction mechanisms

5. Collaboration-based design

1. From Analysis To Design

  • Entire system as an object
  • Physical partitioning onto machines
  • Analysis classes → design classes++
  • Relationships/constraints are the key

2. System Design

  • Architecture; architectural styles
  • Concurrency (default: one thread / object)
  • Physical design (allocate tasks to processors)
  • Data stores (database vs. files; locks; protocols)
  • Control (external / internal)
  • Boundary conditions (e.g. handling failures)
  • Trade-off priorities

3. Object Design

a. Methods

b. New classes

c. Implementing relationships

d. Misuses of inheritance

e. Implementing control

f. Refactoring

g. Abstract classes, interfaces, types

h. Information hiding (visibility)

b. New Classes

  • For intermediate results
  • To implement relationships
  • For abstraction (abstract classes)
  • Interfaces

c. Kinds Of Relationships

  • Generalization
    • Subclasses
    • Enumeration typed attributes
  • Association
    • Aggregation
    • Composition
    • General structural relationship
  • Dependency ( uses )
    • Method or constructor call
    • Attribute or global object
    • Argument passing; return value
    • Passing this

Principle Of Substitutability Liskov

  • If S is a subtype of T, then objects of type T in a program may be substituted with objects of type S, without altering any of the desirable properties of that program – Wikipedia
  • Child has all visible attributes, operations, invariants, relationships and behaviors as parent
  • Question: consider vegetarians and their complement (people who eat vegetables and meat). Which should be the parent class and which the child?

Implementing Associations

  • Factors to take into account
    • Directionality
    • Cardinality
    • Access (CRUD): create, read, update, delete
  • Invariant maintenance (referential integrity)

Pointers

  • One directional (functional): use pointers
    • Example: Foo associated with Bar
    • One-to-one or one-to-many, one way navigation Object of class Foo Methods Var 1: Var 2: Association 1: Bar instance 1 Bar instance 3 Bar instance 2 Bar instance 4

Associations As Objects

  • Implement an association between classes Foo and Bar by introducing a new (association) class: Foo_Bar_ASSOCIATION having two reference attributes: - Foo_INSTANCE - Bar_INSTANCE
  • One instance of the association class (link) for each pair of FOOs and BARs that are associated
  • Foo and Bar still have to access the association

Tables For Associations

  • Use a collection class (hash table, set,

array) to hold all pairs of associated

  • FooObject objects
  • FooObject
    • FooObject
  • FooObject
  • FooObject
  • FooObject
    • FooObject
  • FooObject - BarObject - BarObject - BarObject - BarObject - BarObject - BarObject - BarObject - BarObject

Association Maintenance

  • Associations express a structural relationship between instances of the incident classes
  • When an instance changes it may become necessary to adjust the implementations of the constituent links of the association - For example, in a marriage relationship, if one spouse dies, the link between the two is broken. This might mean deleting a pointer in the spouse or removing a link entry from a table
  • These kind of situations are called referential integrity constraints in the database world
  • Failure to handle them is a notorious source of bugs

e. Implementing Control

  • Ad hoc
  • State machines
    • Program variables
    • Tailored code
    • Table-driven interpreter

f. Refactoring

  • Factoring: moving common features to

the parent class

  • Reduces redundancy
  • Enforces a design constraint
  • Refactoring: moving features around an

existing class hierarchy in order to

improve elegance and reuse