Download presentation
Presentation is loading. Please wait.
Published byMarvin McDaniel Modified over 8 years ago
1
CLASS DIAGRAMS A classy approach to objects
2
The Basic Class Diagram Class Name Attributes (- indicates private each would have properties or accessor/mutator methods) Class Methods Customer ClassElements
3
Class Relationships Classes have relationships with other classes These fall into 4 different kinds Associations Inheritance (generalization/specialization) Aggregation (parts to whole, where parts have a separate existence) Composition (parts to a whole where the parts do not have a separate existence
4
Associations Associations means that a class interacts with another class A customer for instance interacts with a purchase These associations can also contain a property called “multiplicity” Multiplicity specifies how many instances of each class an association a class can have For instance one customer can have many (1..* ) purchases, or one class can have 25 students (1..25)
5
Association Example
6
Inheritance In Inheritance child classes inherit from a parent class This means they get all the public properties and methods of the parent without having to rewrite them Usually the parent is a generalized class that contains all the elements the child classes have in common, and the child classes represent more specialized instances of that general class
7
Inheritance Example
8
Aggregation Aggregation exists when classes have a whole, part relationship but the parts have an independent existence of their own For instance a company exists of many parts, but each of those parts can be treated as an object in themselves
9
Aggregation Example
10
Composition Composition describes a relationship where the parts cannot have a separate existence from the whole. An example is the.Net DataTable class. It contains the classes DataRow and DataColumn, but they can only exist in the DataTable class
11
Composition Example
12
Interfaces Interfaces contain only method definitions. They are often referred to as “contracts” When a class implements an interface it “contracts” to provide an implementation for all the methods in the interface Interfaces are useful for ensuring the consistency of some kinds of common functionality. A developer knows that if a class implements a particular interface then it will contain definitions for the interfaces methods
13
Interface Example Both classes must implement the three methods, as well as their own methods
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.