Download presentation
Presentation is loading. Please wait.
Published byLogan Hudson Modified over 9 years ago
1
Class Relationships Lecture Oo10 Dependencies
2
References n Booch, et al, The Unified Modeling Language User Guide, Chapt 5 p.69, Chapt 9 130, Chapt 10 p.137. n Gamma, Helm, Johnson, Vlissides, Design Patterns, AWL, 1995
3
Teaching Points n Dependency n Parameterized Classes n Abstract Factory
4
Review n What is the difference between aggregation and composition? n Factory Method
5
Dependencies n A dependency exists between to classes (or other elements) if changes to the definition of one element may cause changes to the other n Ideally we are considering changes to interface n not as strong as an association relationship
6
Dependencies n An object of one class creates an object of another class
7
Dependencies n 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 n one class mentions another as a parameter to an operation
9
Parameterized Class n Classes hide and manipulate data/objects n 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 n Parameterized classes allow types to be a parameters in the class or function definitions
10
Parameterized Class n Used mainly for containers –sometimes for other novel implementations n Also known as –“Templates” in C++ –“Generics” in Ada
11
Example n Stacks are a general concept n We might want to have stacks of int, char, complex, or some other user defined objects n 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 n Here T is a type parameter
13
Binding Relationship n Sometimes called “instantiation” –Note: this is not the same as object instantiation n A new class created by specifying an actual type is called a “bound element” n “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 List { void add(E x); Iterator iterator(); } class LinkedList implements List { // implementation } class AnotherClass { LinkedList strList = new LinkedList (); someMethod() { strList.add(“Hello, World!”); string returnStr = strList.getHead(); }
16
Parameterized Classes vs. Generalization n A bound element (instantiated class) is a “kind-of” the parameterized class n But this is not Generalization n Binding merely restricts the type(s) used but the interface remains the same n 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 n Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
20
Teaching Points n Dependency n Parameterized Classes n Abstract Factory
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.