Sunday, October 26, 2008

Section 2.1: UML for Classes, Inheritance, and Memebr Visibilty

Requirement: Recognize the UML representation of classes, (including attributes and operations, abstract classes, and interfaces), the UML representation of inheritance (both implementation and interface), and the UML representation of class member visibility modifiers (-/private and +/public).


(Almost all of this section is just a refinement of the free hfoo-associateuml.pdf pdf file. Unfortunately the link to the pdf is currently broken so I won't be able to give it to you. I will upload the pdf later and provide the link in a downloads section on the blog.)


UML for Classes and Objects:

(2.1.1) A class is drawn as a rectangle with 3 sections:
  1. The 1st section contains the name of the class written in bold.
  2. The 2nd section contians the atrributes (member fields) written as attributeName : AttributeType (ex: title : String).
  3. The 3rd section contains the operations (methods) written as operationName(OperationArgumentTypes) : ReturnType (ex: search(String) : boolean).

(2.1.2) An object is drawn as a rectangle with 2 sections:

  1. The 1st section contains the name of the object as well as its type written as objName : ObjType (ex: hfJava : Book). Note the underlining.
  2. The 2nd section lists the member field names as well as their current values written as attributeName = CurrentValue (ex: title = "HF Java").

(2.1.3) It is less common to use object diagrams but they can be useful for describing specific examples or complex relationships between objects. (2.1.4) In object diagrams, we don't bother listing object operations since all objects of a particular class have the same set of operations so it would be redundant to list the operations for every single object. (2.1.5) Any thing in a UML diagram that is abstract is written in italics (ex: when drawing an abstract class digram we write ClassName in the 1st section of the diagram instead ClassName) (ex: when listing an abstract operation in a particular class or interface we write operationName instead of operationName). (2.1.6) Interfaces are represented just like classes with only one difference which is: we write <> in italics above the name of the interface and of course we write the name of the interface in italics.


UML for Inheritance:

(2.1.7) In UML inheritance is refered to as generalization. (2.1.8) Generalization is reperesented be an open rectangle that points from the subclass to the superclass. (2.1.9) It's also valid to use a single triangle with multiple lines connected to it when connecting many subclasses with the same superclass. (2.1.10) A class that impelements an interface is conneced to that interface by a dashed line with an open triangle pointing to the interface at the end of the dashed line. (2.1.11) When a class implements multiple interfaces, the lollipop notation is used to make drawing the UML diagram more managable. (2.1.12) In lollipop notation the interface is represented by a small circle attached to the class by a solid line. (2.1.13) In lollipop notation we don't list the operations of the implemented interfaces.


UML for Member Visibility:

(2.1.14) To represent a private member field or operation, you preceed the name of the field with the - indicator (ex: - title : String). (2.1.15) To represent a public member field or operation, you preceed the name of the field with the + indicator (ex: + search(String) : boolean).


(Approximately all of the material written here is taken from the references mentioned in the first post. I don't claim to have authored any part of this material . I just compile my own notes from one or many of these references).

2 comments:

Tchulda said...

It would be nice if there were some diagram examples.

Tchulda said...

It would be nice if there were some diagram examples.