Describing Java classes in UML

Source: Internet
Author: User

The Java Programmer's perspective on UML and Object modeling is a simple and practical introduction. While it's fascinating to explore UML from the historical and basic concepts, we'll start with Java code, see how UML Describes Java classes, and insert some knowledge of history and basic ideas into the narrative process.

UML Class Diagram

In Java, we declare two common classes with the following code, each Java class put into a file, the name of the file is the Java class name plus the extension. Java:

public class Person{}
public class Organization{}

UML is the abbreviation of Unified Modeling Language, namely "Unified Modeling Language". Unlike Java, UML is a graphical modeling "language" that uses a rectangle to represent a class, a class name in the interior of a rectangle, and a class diagram that can be put into multiple classes. Using rectangles to represent classes is a function of U (Unified) in UML. In the first version of UML, each object modeling expert has its own set of symbols, some people use dots to represent classes, some use circles to represent classes, and others use rounded rectangles to represent classes. Obviously, this can easily lead to confusion. Later, the three experts of rational company--grady Booch, James Raumbaugh, Ivar Jacobson reached a consensus, agreed to "unify" their respective use of the symbols, UML finally created, the symbol of the struggle has finally come to an end. Figure one is the UML class diagram of the two Java classes above:

Figure a simple class diagram with two classes

UML class diagrams are useful if you want to describe the internal structure of a series of classes and how they relate to each other. For example, in many books, we can see the authors use class diagrams to describe the relationships between classes.

Obviously, an empty class has no practical meaning. We'll add some instance variables and simple methods to the person class. The following is the code for the Person class, which has been simplified and does not contain any comments:

public class Person {
private String name;
private String socialSecurityNumber;
private Date dateOfBirth;
private String emailAddress; 
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getSocialSecurityNumber()
{ return socialSecurityNumber; }
public void setSocialSecurityNumber(String socialSecurityNumber)
{ this.socialSecurityNumber = socialSecurityNumber; }
public Date getDateOfBirth() { return dateOfBirth; }
public void setDateOfBirth(Date dateOfBirth)
{ this.dateOfBirth = dateOfBirth; }
public int calcAgeInYears()
{/*not implemented yet*/return 0;}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.