Class Relationships - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Class Relationships

Description:

Gamma, Helm, Johnson, Vlissides, Design Patterns, AWL, 1995. Teaching Points. Dependency ... A dependency exists between to classes (or other elements) if ... – PowerPoint PPT presentation

Number of Views:103
Avg rating:3.0/5.0
Slides: 21
Provided by: elect77
Category:

less

Transcript and Presenter's Notes

Title: Class Relationships


1
Class Relationships
  • Lecture Oo10
  • Dependencies

2
References
  • Booch, et al, The Unified Modeling Language User
    Guide, Chapt 5 p.69, Chapt 9 130, Chapt 10 p.137.
  • Gamma, Helm, Johnson, Vlissides, Design Patterns,
    AWL, 1995

3
Teaching Points
  • Dependency
  • Parameterized Classes
  • Abstract Factory

4
Review
  • What is the difference between aggregation and
    composition?
  • Factory Method

5
Dependencies
  • A dependency exists between to classes (or other
    elements) if changes to the definition of one
    element may cause changes to the other
  • Ideally we are considering changes to interface
  • not as strong as an association relationship

6
Dependencies
  • An object of one class creates an object of
    another class

7
Dependencies
  • An object of one class sends a message to another
  • but the sending object is not responsible for
    keeping track of the receiving object (which
    would be association)

8
Dependencies
  • one class mentions another as a parameter to an
    operation

9
Parameterized Class
  • Classes hide and manipulate data/objects
  • Often we want to specify the way in which
    data/objects are stored and manipulated without
    actually specifying the actual type of the
    data/objects
  • Parameterized classes allow types to be a
    parameters in the class or function definitions

10
Parameterized Class
  • Used mainly for containers
  • sometimes for other novel implementations
  • Also known as
  • Templates in C
  • Generics in Ada

11
Example
  • Stacks are a general concept
  • We might want to have stacks of int, char,
    complex, or some other user defined objects
  • We would like to describe stacks in terms of some
    unknown type (say T), a type parameter, and
    provide an actual real type when we need a stack.

12
Example
  • Here T is a type parameter

13
Binding Relationship
  • Sometimes called instantiation
  • Note this is not the same as object
    instantiation
  • A new class created by specifying an actual type
    is called a bound element
  • Binding is a kind of dependency relationship
    between a class which is a bound element and a
    parameterized class

14
Example
  • Here complex is an actual type which is
    substituted for the type parameter T

15
Java Example
interface ListltEgt void add(E x) IteratorltEgt
iterator() class LinkedListltEgt implements
ListltEgt // implementation class
AnotherClass LinkedListltstringgt strList new
LinkedListltstringgt() someMethod()
strList.add(Hello, World!) string
returnStr strList.getHead()
16
Parameterized Classes vs. Generalization
  • A bound element (instantiated class) is a
    kind-of the parameterized class
  • But this is not Generalization
  • Binding merely restricts the type(s) used but the
    interface remains the same
  • Instantiation provides no mechanism for adding
    new functionality (state or interface)

17
Parameterized Classes and Generalization
  • Note Alternate notation for binding

18
Abstract Factory Pattern
  • Provide an interface for creating families of
    related or dependent objects without specifying
    their concrete classes.

19
(No Transcript)
20
Teaching Points
  • Dependency
  • Parameterized Classes
  • Abstract Factory
Write a Comment
User Comments (0)
About PowerShow.com