110 likes | 263 Views
An Introduction to UML. COMS 103 section 4 13 January, 1999. Review. UML is a graphical “design” language. Symbols in UML have certain meanings. “Class” is a rectangle with three parts: Name Variables or Attributes Methods. Review (continued).
E N D
An Introduction to UML COMS 103 section 4 13 January, 1999
Review • UML is a graphical “design” language. • Symbols in UML have certain meanings. • “Class” is a rectangle with three parts: • Name • Variables or Attributes • Methods
Review (continued) • Classes have different types of “relationships” • Associations: existence-independent • Dependency: using-relationship • Aggregate: part-of, has, or whole-part
Inheritance Relationships • Define new classes in terms of old classes • This can be a labor-saving mechanism • Sometimes called an “is-a” relationship • Example: • Consider a “computer system” • Refine to a pentium-class computer system • Refine further to a pentium II or Celeron
Inheritance Example Diagram Simulate Computer Operation Computer System Pentium-Class System Macintosh Pentium II Celeron
Inheritance Terminology • Parent/Child • Ancestor/descendent • Superclass/Subclass • Generalization/Specialization • Arrows point toward the more general class • “Inherit” is a verb, as in: • class A inherits from class B • “Inherited” is an adjective, as in: • method doit() is inherited from class B
Inheritance Notation • class superclass { void m1(); } • class subclass extend superclass { void m2(); } • Instance creation: • superclass s1 = new superclass(); • subclass s2 = new subclass(); • Reference: • s2.m1(); • s2.m2();
Overriding Superclass Names Pentium-class doInstruction(int i) • Use Same Name • “super” notation void m1() { super.m1(); // other m1 work } Pentium-II doInstruction(int i)
Inheritance Example Diagram Computer System Pentium-Class System doInstruction() Macintosh Pentium II doInstruction() Celeron doInstruction()
Which “Relationship” to use? • Use Aggregate when creating an instance of one class without the other doesn’t make sense. • Use Dependency when one class provides a service to the other. • Use Association when neither class depends upon the other, but there is a relationship. • Use Inheritance when one class is a special case of the other.
Relationship Notation Review • Aggregate: • Dependency: • Association: • Inheritance: