Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 1: Java and Eclipse UML. Depending on the source, the acronym UML is said to stand for “unified modeling language” or “universal modeling language”.

Similar presentations


Presentation on theme: "Unit 1: Java and Eclipse UML. Depending on the source, the acronym UML is said to stand for “unified modeling language” or “universal modeling language”."— Presentation transcript:

1 Unit 1: Java and Eclipse UML

2 Depending on the source, the acronym UML is said to stand for “unified modeling language” or “universal modeling language”. In any case, it is a set of conventions that can be used to diagram object-oriented software. It is possible to pictorially represent things like classes and their methods and instance variables; objects of those classes; relationships between classes; and so on.

3 These notes will not give complete coverage of UML. However, at various points in the presentation of Java it may be helpful to represent an idea or relationship visually. In those cases, the corresponding UML notation will be introduced and used for that purpose.

4 UML has a vocabulary as well as a set of visual symbols which are used to represent object- oriented components. The terms “class” and “object” have already been used in these notes. These terms are used to mean the same thing in UML.

5 The terms “instance variable” and “method” have already been introduced. The corresponding terms in UML are “attribute” and “operation”. There is more than one object-oriented language. UML is neutral. An object-oriented program in any of these languages could be described using UML terminology.

6 Since this book only covers Java, the terms “instance variable” and “method” will continue to be used. It should be noted that in the official Java documentation, the term “field” is used for “instance variable”. Since this is the term chosen by the language designers, in some sense it may be more technically correct. However, the term “field” may be confusing because it has other uses in various programming environments. “Instance variable” will be used instead because it is more descriptive.

7 In order to illustrate UML, it is necessary to have an example. It is possible to introduce such an example and talk about object-oriented ideas without even knowing any Java. The example which will be continued throughout the notes is based on the following idea: It is possible to store seeds in a cup.

8 This may seem a little impractical. You typically think of a cup as containing a liquid, and it’s not clear what kinds of interesting programs you might write involving cups and seeds. Any introductory example of a class would tend to be impractical anyway. The cup and seed example is given because it is a component of a game program which is developed later on in the notes.

9 Classes and objects are represented using rectangles in UML. Relationships are represented using labels, lines, arrowheads, and other symbols. In its simplest form, a class can be represented by a rectangle containing the name of the class. The name is capitalized and given in bold face. For example, this would represent the Cup class:

10

11 An object of a given class would have a name of its own. Say an instance is known as “my coffee mug”. It is also represented by a rectangle. The name is not capitalized. It is followed by a colon and the name of the class it is an instance of. All of this is underlined. For example:

12

13 The relationship between the class and the object can be graphically shown with an arrow. It turns out that in UML different kinds of relationships are shown with different kinds of arrows, so the form of the arrow is important. This relationship is shown with a dashed arrow with an open, or feathered arrowhead. The arrow points from the object to the class.

14

15 More detail about a class can be given by including its attributes and operations in the diagram. In general, such a class diagram takes this form:

16

17 To be specific, let the Cup class have one instance variable, named seedCount. Let the class have two methods, setSeedCount() and getSeedCount(). Let the seedCount be an integer, and when a new instance of the class is created, let its seedCount be initialized to the value 0. The setSeedCount() method assigns a value to the seedCount of an object. The getSeedCount() method returns the value currently stored in the seedCount variable, whatever that may be. This information is shown in this more complete form of the class diagram:

18

19 It is also possible to give even more detail, including information about the parameter of the setSeedCount() method, ranges of valid values, or other information, for example. The diagrams are used to document a software system, a program, or its components. The level of detail included should be gauged to be helpful to the intended reader of the diagram, whether a designer, a programmer, or a program user.

20 Section Summary UML is used for diagramming object-oriented programs. UML has a vocabulary for the components of classes. Java has its own, parallel vocabulary for the components of classes. The cup and seed example is used for the purposes of illustration.

21 In UML classes and objects are represented by rectangles and relationships are represented by arrows and other symbols and labels. A simple class diagram is a rectangle containing the capitalized name of the class in bold face. A simple object diagram is a rectangle containing the name of the object followed by a colon and the name of its class, all in bold face.

22 The relationship between an object and its class can be shown by a dashed arrow with an open arrowhead from the object to the class. A more complete class diagram includes the class’s attributes and operations, possibly along with more detailed information. The level of detail in diagrams can vary.

23 Vocabulary UML. Attribute. Instance variable. Field. Operation. Method.


Download ppt "Unit 1: Java and Eclipse UML. Depending on the source, the acronym UML is said to stand for “unified modeling language” or “universal modeling language”."

Similar presentations


Ads by Google