220 likes | 402 Views
Structural Modeling: Class Diagrams. Class Diagrams. Provide static view of system Most common type of diagram in OOAD Forms basis for component and deployment diagrams Shows Classes Interfaces Collaboration And their relationships. Classes. Definition of the word “ class ”
E N D
Class Diagrams • Provide static view of system • Most common type of diagram in OOAD • Forms basis for component and deployment diagrams • Shows • Classes • Interfaces • Collaboration • And their relationships
Classes • Definition of the word “class” • Oxford: “a number of individuals having a character or feature in common” • Webster: “a number of persons or things regarded as forming a group by reason of common attributes, characteristics, qualities or traits”
Classes in everyday life… • Based on similar values for a particular, or group of attributes • All purple dinosaurs; all green apples; all Jesuits • Based on the range of an attribute • Everyone who is between 18-21 years of age • Based on similar behavior • Everyone who sleeps in class; everyone in the ECIS program
All about Classes • Based on the notion of abstraction • Starts with identification of all common characteristics of a set of elements • All objects belong to a class • Objects represent an instance of a class • Software objects are built from a class through instantiation
Representation of a Class CLASS NAME Attributes Operations ( )
Representation of a Class MOTORCYCLE Color Maximum Speed Engine Start ( ) Brake ( )
Purpose of Class Diagrams • To model the vocabulary of the system • What lies within and without the system • To model simple collaborations • To visualize the relationship between classes • To model a logical database schema • Three major types of constructs in class diagrams • Inheritance structure • Association structure • Aggregation structure
Additional Concepts • Aggregation • A relationship between two classes where the instances of one class are, in some way, components, members , or contents of the instances of the other class (from Brown, 2002) • Types • Component (assembly) • Container (contents) • Collection (Member)
Aggregation: Component Car Engine Transmission Body Consists of Car Part
Class Hierarchies Vehicle Land Air Car Bike Plane Helicopter (referred to as “Generalization”)
Problems with Classification Animal Two-legged Four-legged Herbivore Carnivore Herbivore Carnivore Why should I classify this way instead of…
Class Hierarchies Animal Herbivore Carnivore 2 legs 4 legs 2 legs 4 legs This way?
Multiple Generalization Animal Herbivore Carnivore Two Legged Four legged Dog
Subclass Partitioning • Disjoint vs. Overlapping • Based on mutually exclusive subgroups • Incomplete vs. Complete • Coverage of the entire set Powered Vehicle ANIMAL Disjoint and incomplete Overlapping and complete Plane Car Truck Herbivore Carnivore
Relationships Between Classes • Associations • Objects are linked • Classes are associated • Represented as (a link) SU: University David: Student University Student (an association)
Multiplicity • Sometimes called the “cardinality”of a relationship • The number of instances of each class that are or can be involved in a given association 1 University Student *
Other Examples * Driver Bus * * Customer Product * * Student Course * 1 Advisor Student *
Roles and multiplicity 1 University Student * 0..1 University Teacher * May be replaced by.. teacher employer * 0..1 University Person 1 * student
An example Aggregation (composed of..) COMPANY located OFFICES DEPARTMENT Address: Stringvoice: number Name: Name constraint association * * roles {subset} generalization member 1..* manager 1 PERSON HEADQUARTERS Name: NameempID: IntegerTitle: String interface Getphoto() Getsound() Getcontact() Getpersrec() PersonnelRecord taxId: string Salary: currency
Generalization vs. Aggregation • Can sometimes be confusing • Distinction can be made based on verb used • Generalization • The phrase: “IS A KIND OF…” • “A car is a kind of vehicle” • Aggregation • The phrase: “HAS A/AN…” • A car has an engine
An Example BURNING LAMP LAMP ELECTRIC LAMP BASE WIRE SWITCH INCANDESCENT FLOURESCENT SOCKET BULB