First, class diagram 1. In the UML class diagram, the class name is a correct word, which is a specific class; the class name is the oblique word description is an abstract class. The class chart has a total of five layers, the first is the class name (not omitted), others can be omitted, in turn is the attribute layer (defined variable), method layer, nature layer (consisting of internal variables, assignment functions, value ", , SET, implement parent class and interface. There is reputation before the method is public, and it is private if the front is #, indicating is protected. If there is a next line, it is a static method. 2. The relationship between class diagrams generalization generalization: indicates the inheritance relationship between classes and classes. Extends, IMPLEMENTS, is represented by a triangular arrow. Association: A class knows the properties and methods of another class. It is achieved by instance variables. It can behave as the relationship between N..m. Attention is in the same level. Expressed with a solid arrow. AGGREGATION: It is a strong relationship, aggregation is the relationship between the overall and individuals. Also achieved by instance variables, between classes are inequality levels. Expressed with an empty rhombus. It is also known as delegation. Composition: Compared to aggregate relationships, the whole should be responsible for part of the life cycle. Synthetic relationships cannot be shared. Diamonds with black entities. Dependency: is a one-way, represented by a virtual arrow. The dependent class has no dependencies, which is incorporated by parameter. Realize: Displays the relationship between classes and interfaces, packages and interfaces, and use cases and use case implementations. Add a triangular arrow with a dashed line. Second, the maintenanceability and reusability of the object 1. On-Closed Principles (OCP): A software entity should open the extension and close to modify. Software Entities Should Be Open for Extension, But Closed for Modification.2. Implementation: The abstract layer of the system is not allowed, and the implementation layer of the extension system is allowed. Therefore, the key to the problem is that abstraits and the variability package. Abstract, extracts all the specific classes must be provided by the method of the method as the abstraction layer of the system design; and variability should not be scattered in all the code, but should be packaged into an object. Third, the implementation of the specific Java language 1. Interface: From the ASP turn, I have never understood the Java interface, here I saw a metaphor.
At home, it is easy to unplug the microwave from a power outlet, then plug in the laptop. For sockets, these appliances are insertable components, which can be inserted because they have a plug that matches the socket. The so-called interface is actually equivalent to the power outlet. The interface is the key to the insertability of the component.
The Java Interface (Interface) is a collection of methods. The interface only features the features, and not implementation, it can also define the constant of public.
There is another metaphor for the implementation of the interface.
The interface often represents a role (Role), which is packaged with the role related operations and properties, and the class that implements this interface is an actor who plays this role. One role can be played by different actors, while different actors do not need to be all common in addition to playing a common role.
2. Why use the interface in one sentence: No interface, the insertability is not guaranteed. Any class in a class level structure can implement an interface, which will images all subclasses of such a class, but not any superclars in this class. This class is to implement all the methods of the interface, and its subclasses can be automatically inherited or selected to overload these methods. The most attractive one:
As mentioned in front, an object needs to complete a task, you need to know other objects, call the method of other objects. If this association is not for a specific class, it is for an interface, then any class that implements this interface can meet the requirements. In this way, this association can be dynamically converted from a specific class to another, as long as these classes implements an interface. Similarly, if an object needs to call other objects, this call comes from an interface. Then any particular class that implements this interface can be called by the current object, and the current object is a specific class of the instance of the specific class that is fully dynamically.