Designing Java applications with UML class diagrams (i)

Source: Internet
Author: User
Tags abstract

UML has become the standard graphical tool of object-oriented design, in the various graphs of UML definition, this article only involves class diagram. Java applications are composed of many classes, and the design and implementation of class diagrams is the core of Java implementation object-oriented applications. This article through a specific application of the design and implementation process, detailed description of the use of UML class diagram design Java applications, making the development process standardization, visualization, code programming simplification.

In a class diagram, a class is described as a box with a three-layer.

The top level is the class name, which is generally indicated by bold font. If the class is abstract, the name is expressed in italics, and if the class is an interface, the <<interface>> is labeled above the class name.

The middle tier contains the properties (or variables) of the class, and the underlying method that contains the class. Similar to the class name, if the method is abstract, its name is also expressed in italics.

We are designing application Cdrawapp applications that draw dots, boxes, and text strings on character-based grids that involve many Java object-oriented concepts and applications that are very systematic and comprehensive, and will quickly master UML class diagrams After you have studied them. and apply it to the actual Java application development process. To reduce the length of the code to make the program easy to understand, here Use the Java Console window to display the results of the program run. The program consists of 10 major categories, which are described separately below.

One, point class

The first class defined in the Cdrawapp program is the point class, which is used to identify a dot on the grid through the X and Y coordinates. The class diagram is designed to:

In this class, there are 2 member variables x and Y, and in the class diagram, "-" indicates that the variable or method is private, "+" means public, and "#" means protected. This class defines three different constructors, which is an example of overloading (overload).

The class then designs 7 access methods. The GetX () and Gety () methods return a point of X and Y coordinates, respectively. The SetX () and Sety () methods set the values of these coordinates based on the values of the parameters Xvalue and Yvalue. The two Add () method creates a new point object by adding a value to the coordinates of the access points. The new operator creates a fresh instance of the class. It is followed by the constructor that initializes the new build instance. ToString ()

method returns an object of the class string that describes a point with an ordered pair.

According to the design of the class diagram, its Java implementation code is:

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.