Advantages of the object-oriented development approach

Source: Internet
Author: User

First look at the structured approach to software development

1. Structured Software Development methodology

The SASD method can also be referred to as a function-oriented software development method or a data flow oriented software development approach. The SASD method is the most widely used software development method in the the 1980s. It first uses the structural analysis (Structure Analysis,sa) to analyze the requirements of the software, then uses the structured design (Structure design,sd) method for the overall design, and finally carries on the structured programming (Structure programming, SP). This development method makes the development step clear, SA, SD and SP complement each other, one go.

The structural development method mainly divides the software structure according to the function, it regards the function of the software system according to the given input data, carries on the corresponding computation, then outputs the result,

In the structured design, the function of the whole software system is considered first, then the function is decomposed according to some basic principles (such as cohesion and loose coupling), and the whole software system is divided into several modules, each module realizes specific sub-functions. In order to improve the cohesion of the software, the function is decomposed into smaller sub-modules in the module. After all the modules have been designed, the modules are assembled to form the entire software system. Software system can be regarded as a collection of subsystems, each subsystem has the function module of input and output.

Structured design is a top-down design, in the design phase has to consider how to implement the function of the system, because the process of decomposition function is actually the process of realizing the function. The limitation of structured design is that it cannot flexibly adapt to the changing needs of users. When user requirements change, it is necessary to modify the structure of the module from top to bottom, and sometimes even the entire software system design is completely overturned.

Disadvantages:

A, from top to bottom according to function to partition software modules. The function of the software is not invariable, it will change with the user's demand, which makes it difficult to design a stable system structure in the design stage.

B, the smallest subsystem in the software system is the method. Method and part of the related data separation, global variable data and constant data scattered in all corners of the system, which weakens the relative independence between the various systems, thus affecting the maintainability of the software.

2. Introduction to Object-oriented software development methods

The object-oriented development method regards the software system as a collection of objects, which is the smallest subsystem, and a group of related objects can be combined into more complex subsystems. The object-oriented development approach has the following advantages.

A, the software system as a collection of various objects, which is closer to the natural way of thinking of human.

B, changes in software requirements are often the function of the change, and the function of the performer-object generally will not have a big change. This makes the system structure based on the object design more stable.

C, the object includes attributes (data) and behavior (methods), the object of the data and methods of the specific implementation of the package together, which makes the method and the data associated with it no longer separate, improve the relative independence of each subsystem, thereby improving the maintainability of the software.

D, support encapsulation, abstraction, inheritance and polymorphism, improve the reusability, maintainability and expansibility of software.

2.1. Object Model

In the object-oriented analysis and design phase, the object model of simulation problem domain is set up. Building an object model includes both a bottom-up abstraction process and a top-down decomposition process.

(1), bottom-up abstraction

The first step in building an object model is to start with a statement in the problem area. The process of analyzing requirements is consistent with the formation of the object model, and the conversation between the developer and the user begins with the things that are familiar to the user in the area of the problem (specific instances), which gives the user and the developer a common language, allowing the developer to thoroughly understand the user's needs and then establish the correct object model. Developers need to do the following bottom-up abstraction.

A, to abstract things in the problem domain into specific properties and behavior of the object.

B, abstract objects with the same properties and behaviors as classes.

C, if there are some commonalities between multiple classes (with the same attributes and behavior), these commonalities are abstracted into the parent class.

In a bottom-up abstraction, a top-down modification may be required for subclasses to more rationally inherit the properties and behavior of the parent class, making the whole class system more reasonable. Because the structure of this kind of system is from concrete to abstract, then from abstract to concrete, accord with the law of human thought, so it can accomplish task faster and more conveniently. This is in stark contrast to the top-down structured development approach.

(2), top-down decomposition

The top-down decomposition is also included in the process of building the object model. For example, for a computer system, the host object, display object, keyboard object, and printer object are identified first. These objects are then further decomposed, such as host objects such as processor objects, memory objects, hard disk objects, and motherboard objects.

2.2. UML Visual Modeling Language

The concept and genre of object-oriented analysis and design method are different, it is necessary to use a unified symbol to describe the object model in software analysis and design stage, UML (Unified Modeling Language, Unified Modeling Language) came into being. UML is a well-defined, easy-to-express, powerful and universally applicable visual modeling language. It absorbs the merits of many schools, and further develops, and eventually becomes the standard modeling language accepted by the public.

2.3. Rational Rose Visual Modeling Tool

Rational Rose is a visual modeling tool developed by rational, which uses UML language to build object model and is a powerful tool for analyzing and designing object-oriented software systems.

3. Core ideas and concepts in object-oriented development

In the process of object-oriented software development, the main task of the developer is to establish the object model of the simulation problem domain and then implement the object model through program code. How to establish object model, how to implement object model with program code, and guarantee reusability, extensibility and maintainability of software system? This is not a question that can be answered clearly in two or three words.

3.1. Problem domain, object, attribute, state, behavior, method, implementation

The problem domain is the real-world system that the software system simulates. With the development and popularization of computer technology, the software system permeates all aspects of society and can be used to simulate any kind of problem field, and object is the abstraction of things in the problem domain. objects have the following characteristics:

A, all things are objects.

B, each object is unique. The uniqueness of an object comes from the uniqueness of things in the real world.

C, the object has properties and behavior. The behavior of the object includes the functionality and the specific implementation. In the model phase of building an object, you simply focus on what functions the object has, without having to consider how to implement the functionality.

D, the object has a state. State refers to the value of each property of an instantaneous object.

E, objects belong to a class, and each object is an instance of a class.

3.2. Class, type

A class is an abstraction of a set of objects that have the same properties and behavior. The relationships of classes and classes form the main content of the object model. As shown in Fig. 1-9, the object model is used to simulate the problem domain, the Java program implements the object model, and the Java program runs in the runtime environment provided by the Java Virtual machine, and the Java Virtual machine runs on the computer.

The main task of object-oriented programming is to define the various classes in the object model.

3.3. Message, Service

The complex function of software system is accomplished by various objects working together. This collaborative relationship is implemented by sending messages, and the services provided by the object are implemented by the methods of the object, so that the occurrence of the message is actually a method of invoking an object.

3.4. Interface

Since each object is a service provider, how can we provide services externally? Objects are serviced externally through an interface. In the real world, the interface is also an entity, such as a power outlet, a button on a washing machine, and a light switch. In the object-oriented category, the interface is an abstract concept, which refers to all the services provided by the system externally. The interface of the system describes what services the system can provide, but does not include the implementation details of the service.

Interface is a powerful means to improve the loose coupling between systems.

In the Java language, interfaces have two meanings:

A, the first refers to the conceptual interface described above, that is, all services provided by the system to the outside, in the object as the public type of method declaration.

B, two refers to the interface keyword defined by the real interface, also known as the interface type, it is used to clearly describe all the services provided by the system externally, it can more clearly the implementation of the system details and interface separation.

3.5, packaging, transparent

Encapsulation refers to the properties and implementation details of hidden objects, and only exposes interfaces externally. Encapsulation can bring the following advantages to software system.

(1) It is easy for users to understand and use the system correctly, to prevent users from mistakenly modifying the system's properties. or the power supply system, for example, in the past the walls of the house are electric wires, and now the houses in the wires are "missing", on the wall only exposed a number of electrical outlets. Why do you want to hide the wires? The reason is simple, the exposed wire is not safe or beautiful.

(2) It is helpful to establish the loose coupling relationship between the systems and improve the independence of the system. When the implementation of a system changes, as long as its interface is not changed, it will not affect other systems.

(3) to provide reusability of software, each system is a relatively independent whole, can be reused in many environments. For example, a dry battery is a reusable, standalone system that works in cameras, flashlights, electric shavers, and toys.

(4) Reduce the risk of building large systems, even if the entire system is not successful, individual independent subsystems may still be valuable.

A well-designed system encapsulates all the implementation details, cleanly isolating its interfaces from the implementation, and communicates only through the interface between the systems. Object-oriented programming language is mainly encapsulated by access control mechanism, which can control the object's properties and the accessibility of methods.

Two main principles are proposed for encapsulation:

(1), to hide as many things as possible, to provide a simple interface

The higher the package of the system, the higher its relative independence, and the more convenient it is to use.

(2), hide all the attributes.

If a property allows access to the outside world, provide a public way to access the property. Why not define a property as a public type and let the user access it directly? This is done for the following reasons:

A, more in line with the real world external factors through the internal effect of the objective law. The change of the property of an object should be the result of the interaction of external cause and internal causes.

B, the ability to control the read and modify the access level of the property flexibly.

C, prevent the user from modifying the property incorrectly. This logic can be easily implemented in SetPassword (), such as when a password is modified, requiring that the password be a 6-digit number.

D, help the object encapsulation implementation details.

One concept that has the same meaning as encapsulation is transparency.

3.6. Abstract

Abstract refers to the process of thinking from a certain point of view, extracting the characteristics of our attention from some existing things and forming a new one. Abstraction is a way of thinking from concrete to abstract, from complex to concise. In the object-oriented development process, the abstract is reflected in the following aspects

1. Abstraction from things in the problem domain to objects in the software model

When the object model is established, the entity in the problem domain is analyzed, and it is abstracted as an object. Things in the real world tend to have a variety of attributes, and objects with specific attributes should be abstracted according to the problem domain in which things are located.

2. Abstraction from object to class

When the object model is established, objects with the same properties and functions are abstracted as classes.

3. Abstraction from subclass to parent class

When some classes have the same attributes and functionality, this part of the property and functionality is abstracted into a parent class. There are two cases of abstraction from a subclass to a parent class:

    • When different subclasses have the same functionality, and the functionality is implemented exactly the same way. For example the parent class of bicycles and tricycles is non-motorized. Bicycles and tricycles have brake functions and are implemented in the same way. In this case, the function is implemented in the parent class, which is not a motor vehicle class, and subclasses do not have to implement this function repeatedly. Provides reusability and maintainability of code.
    • Different subclasses have the same functionality, but the functionality is not implemented the same way. For example, fluorescent lamps and electric lights can be illuminated, but the implementation method is different. In this case, the parent class, the lighting facility class, only declares this functionality, but does not provide a specific implementation. This combination of abstract and object-oriented polymorphism helps to improve the loose coupling between subsystems.

In the Java language, abstractions have two meanings:

    • When abstract as a verb, it is the above-mentioned abstract thought process.
    • When abstractions are adjectives, they can be used to modify classes and methods. If a method is modified by an abstract, it indicates that the method is not implemented in detail, and that if a class is modified by an abstract, it indicates that the class cannot be instantiated, for example, the fluorescent lamp class and the lamp class are abstracted as the parent class-the lighting facility class lighting. The lighting class is an abstract class, its light () method is an abstract method, only describes the function of the lighting class, but it is not implemented, only its sub-class light () method can be implemented.

3.7, inheritance, extension, coverage

There is an inheritance and extension relationship between the parent class and the child class. Subclasses inherit the properties and methods of the parent class, and can also extend the new properties and methods in the subclass, and also override how the methods in the parent class are implemented. Overrides are also specialized terms, meaning that methods in the parent class are re-implemented in the subclass.

Advantages of the object-oriented development approach

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.