Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class Diagram Implementation Introduction Below you have a UML class diagram for a washing machine software control application. It is an object model that represents

Class Diagram Implementation

  1. Introduction

Below you have a UML class diagram for a washing machine software control application. It is an object model that represents the system.

It contains the class diagrams and the class relationships necessary to operate the washing machine. Its purpose is for general conceptual modeling of the structure of the application, and for detailed modeling translating the models into programming code.

This diagram is what a development team might have created and something that might be given to you or your implementation team to translate into code.

image

Figure 1. Washing Machine class diagram

  1. Guidance information

Class diagrams

Each class diagram will show the three parts of the class notation.

A class notation consists of three parts:

  • Class Name
    • The name of the class appears in the first partition.
  • Class Attributes
    • Attributes are shown in the second partition.
    • The attribute type is shown after the colon.
    • Attributes map onto member variables (data members) in code.
  • Class Operations (Methods)
    • Operations are shown in the third partition. They are services the class provides.
    • The return type of a method is shown after the colon at the end of the method signature.
    • The return type of method parameters is shown after the colon following the parameter name.
    • Operations map onto class methods in code
    • image  
    • Figure 2. Example Class Digram

       

      The graphical representation of the class - MyClass as shown above:

      • MyClass has 3 attributes and 3 operations
      • Parameter p3 of op2 is of type int
      • op2 returns a float
      • op3 returns a pointer (denoted by a *) to Class6
    • The +, -, # and ~ symbols before an attribute and operation name in a class denote the visibility of the attribute and operation.

      • + denotes public attributes or operations
      • - denotes private attributes or operations
      • # denotes protected attributes or operations
      • ~ denotes package attributes or operations

    •  

       

      Class Relationships

      A class may be involved in one or more relationships with other classes. A relationship can be one of the following types: (Refer to the figure on the right for the graphical representation of relationships).

      Relationship Type: Inheritance (or Generalization):

      Graphical Representation

image

Figure 3. Inheritance or Generalization Relationship

Represents an "is-a" relationship.

An abstract class name is shown in italics.

SubClass1 and SubClass2 are specializations of Super Class.

A solid line with a hollow arrowhead that point from the child to the parent class.

 

Relationship Type: Simple Association:

Graphical Representation


image




Figure 4. Association Relationship

A structural link between two peer classes.

There is an association between Class1 and Class2.

A solid line connecting two classes.

 


 

 

Relationship Type: Aggregation:

Graphical Representation

image

Figure 5. Aggregation Relationship

A special type of association. It represents a "part of" relationship.

Class2 is part of Class1.

Many instances (denoted by the *) of Class2 can be associated with Class1.

Objects of Class1 and Class2 have separate lifetimes.

A solid line with an unfilled diamond at the association end connected to the class of composite.

 

Relationship Type: Composition:

Graphical Representation

image

Figure 6. Composition Relationship

A special type of aggregation where parts are destroyed when the whole is destroyed.

Objects of Class2 live and die with Class1.

Class2 cannot stand by itself.

A solid line with a filled diamond at the association connected to the class of composite.

 

Relationship Type: Dependency:

Graphical Representation

image

Figure 7. Dependency Relationship

Exists between two classes if the changes to the definition of one may cause changes to the other (but not the other way around).

Class1 depends on Class2.

A dashed line with an open arrow.

 

Relationship Names

Names of relationships are written in the middle of the association line.

Good relation names make sense when you read them out loud:

"Every spreadsheet contains some number of cells",

"an expression evaluates to a value"

They often have a small arrowhead to show the direction in which direction to read the relationship, e.g., expressions evaluate to values, but values do not evaluate to expressions.



image

Figure 8. Class Diagram with Direction of Relationships

 

Relationship - Roles

A role is a directional purpose of an association.

Roles are written at the ends of an association line and describe the purpose played by that class in the relationship.

E.g., A cell is related to an expression. The nature of the relationship is that the expression is the formula of the cell.

 

Navigability

The arrows indicate whether, given one instance participating in a relationship, it is possible to determine the instances of the other class that are related to it.

The diagram above suggests that,

Given a spreadsheet, we can locate all of the cells that it contains, but that we cannot determine from a cell in what spreadsheet it is contained.

Given a cell, we can obtain the related expression and value, but given a value (or expression) we cannot find the cell of which those are attributes.

 

Visibility of Class attributes and Operations

In object-oriented design, there is a notation of visibility for attributes and operations. UML identifies four types of visibility: public, protected, private, and package.

 

  1. Class Diagram - Diagram Tool Example

A class diagram may also have notes attached to classes or relationships.


image

 

Figure 9. Example diagram with explanation of the connections and parts.

In the example above:

  • We can interpret the meaning of the above class diagram by reading through the points as following.
  • Shape is an abstract class. It is shown in Italics.
  • Shape is a superclass. Circle, Rectangle and Polygon are derived from Shape. In other words, a Circle is-a Shape. This is a generalization / inheritance relationship.
  • There is an association between DialogBox and DataController.
  • Shape is part-of Window. This is an aggregation relationship. Shape can exist without Window.
  • Point is part-of Circle. This is a composition relationship. Point cannot exist without a Circle.
  • Window is dependent on Event. However, Event is not dependent on Window.
  • The attributes of Circle are radius and center. This is an entity class.
  • The method names of Circle are area(), circum(), setCenter() and setRadius().
  • The parameter radius in Circle is an in parameter of type float.
  • The method area() of class Circle returns a value of type double.
  • The attributes and method names of Rectangle are hidden. Some other classes in the diagram also have their attributes and method names hidden.

 

  1. Moving a class diagram into code

Below is a class diagram showing three classes Person, Company and Job.

image  

Figure 10. Example class digram

Here is the implementation codes for the class diagram

Class Person {

    Private String name, ssn, addr;

    Job job;

    Person boss;

Public String getName(){  }

Public void setName(string Name){  }

Public String getSsn(){  }

Public String getAdress(){    }

 

}

 

Class Company 

{
    String name, addr;
}
 

Class Job {

    Company co;

    int salary;

    String title;

}

 

Note that the code is not complete.  You only have the initial skeleton of the static model. You would still need to consult the sequence diagrams and any activity diagrams created through your system analysis.

 

 

Take the Washing Machine class diagram shown at the beginning of the Guidance and implement the diagram into java or C# code using eclipse IDE or Visual Studio.

Complete the following:

  • In main (), provide necessary function calls for all created methods.
  • Only provide a print statement for each method that prints out what is does.
  • Compile and run the application to verify there are no errors.
  • Provide a screen shot of your consoler results as well as the source code for every class and or interface created.


+turnOn() +tunOff() < Machine DoorSensor Engine -Rotation:integer |- -engine Sensor +Check(): Boolean TempSensor Washing Machine -washTime:integer -rinceTime:integer -spinTime: integer +main() -wash() -rince -spin() -fill() -empty() -standardWash() -twiceRince() -waterSensor -washOption WaterSensor +curretnLevel:integer +desiredLevel:integet Timer -value:integer -timer. -duration:integer -count: integer +getDuration(): duration +setDuration (int integer) +getValue():time +setValue(int integer) +getCount():count +setCount(int integer) +start() +count():time WashOption -washSelection:integer +getWashSelection(): integer +setWashSelection ():void

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

What is Unicode, and how is it used?

Answered: 1 week ago