Object-oriented and Structured Analysis and Design (reprinted, good article)

Source: Internet
Author: User
Tags qmail
1. Method background

Although structured and object-oriented ideas were both developed in 1960s, they were fundamentally different. The structured method inherits the traditional programming ideas and programming methods, and takes the computer's computing function as the premise. The main purpose of programming is numerical computation and problem solving. The module is the basic unit of structured programming, but the computing method (Algorithm for short) is the core of the program. Wallsen once proposed a famous formula: program = Algorithm + data structure. The structured method only improves the traditional program structure. It uses three basic structures to organize the program, making the program structure clearer and program development more orderly and easier.

The object-oriented thinking is based on the functions of computer information processing and information management to simulate the relationship between things and things in the objective world. The key concepts of object technology are objects, messages, and classes. The key mechanisms include encapsulation, polymorphism, and inheritance. Compared with the structured method, an object is a new unit of software modularization. It replaces traditional technologies such as the so-called "module" in the functional decomposition method. Object-oriented technology implements program functions through Object Management (creation, operation, and extinction) and communication between objects. In the structured method, a module is only a functional (Mechanical) component of a program. It completes a specific function or solves a specific problem in the program. Therefore, modules in the program are usually implemented using functions to process and compute the input data. The object in the object orientation is a living body (a living body), which encapsulates data and processes together, this is in stark contrast to the traditional methods that treat and process data separately. Objects represent the structures and interactions of real objects in the real world. They have a life cycle during the running of the program, and complete program functions through mutual communication.

2. Problem Analysis Methods

Software analysis is an important stage of software engineering. In the software analysis stage, the functions, performance, and running environment constraints of the software to be developed are determined. At the same time, methods and approaches for solving problems or implementing functions are proposed to resolve the complexity of a system, there are usually two solutions. The most basic technology for resolving complexity is to break down a big problem into small problems that are easy to solve. After small problems are solved, the big problems will be solved. The core idea of structured analysis is: top-down, layer-by-layer decomposition, and gradual refinement. Structured Analysis is embodied in the data flow diagram and system structure diagram decomposition process. The data flow graph is decomposed from the top layer graph. According to the decomposition principle of each processing corresponding to a subgraph, the data flow graph is decomposed into a layer-0 graph and a layer-1 graph layer by layer. The system structure diagram is a sub-module that is decomposed from the main module into simpler algorithms, easier to manage and implement.

Object-Oriented analysis uses another method to resolve complexity from the bottom up: abstraction. ABSTRACT To get a simplified model of the system, which emphasizes the details of a certain attribute in the system and ignores other attributes. Object-Oriented Analysis has three levels of Abstraction: first, identifying objects and their attributes and methods, which are the abstraction of objects in the objective world; second, classifying objects layer by layer, abstract The relationship between objective things. For example, similar objects are classified as one type, child classes are classified as parent classes, or local classes are classified as whole classes. Third, objects and classes are further abstracted to a topic to facilitate the definition and Management of classes and objects. The structured analysis method inherits the traditional mathematical problem solving idea and adopts the mathematical deduction method that is gradually improved, which is conducive to solving data processing and computing problems. But the method of gradual refinement cannot provide a system strategy or method to solve a specific problem. Sometimes, there is no top-down method for some problems. Structured program analysis is an effective method for small-scale programs, but it is often ineffective to promote it to large-scale system development, developers cannot use this method to easily reuse reusable components of previous programs. The abstract mechanism of object-oriented methods provides a more natural method for modeling complex software systems, especially to grasp the complex relationships between objects, therefore, object-oriented analysis technology is more suitable for analysis of complex software systems.

3. Programming Method

The structured program design method is opposite to the analysis method, and adopts the bottom-up design idea. First, design the underlying module, determine the internal algorithm of the module, design the internal program of the module, and perform unit tests. After the modules are completed, assemble the modules and perform integration tests. After the module integration test is complete, the validation test and system test are conducted to complete the design and debugging tasks.

The object-oriented programming method adopts the top-down design idea. It first designs the parent class, then child classes, and inherits the attributes and methods of the parent class. The object is generated dynamically during the program running. While designing the class, another task is message design. And organically associate the message with the method in the class, so that the object can communicate with each other during the running process and implement the software setting function together. Messages are similar to function calls in traditional programming languages. The main difference between them is that the functions executed in function calls are a single and public implementation, and the responses to messages can be answered differently, this depends on the method of the specific object. This is the multi-State mechanism of object-oriented programming ideas.

4. Applicable scenarios

The essence of the structured method is problem solving, that is, the structured program is determined by the algorithm, and the algorithm is analyzed and designed by the programmer. Therefore, in a structured method, the execution process of a program is mainly controlled by the programmer rather than the user. This method is suitable for large-scale engineering computing, real-time data tracking and processing, and various automatic control systems.

In object-oriented methods, programmers design object attributes and operation methods. However, when and how objects are operated is completely controlled by user interaction. In the Internet era, computers have gradually evolved from a production tool to a living tool, and many application software completely controlled by users to execute processes have emerged, for example, large game software and various management information system software. The various relationships in these software are complex and suitable for development using object-oriented methods.

5. Example)

Designing with an object-oriented approach is actually a process that abstracts business logic from specific programming techniques. This abstract process is top-down, it is very in line with human thinking habits, that is, to abstract the most important aspects of the problem into a simple framework without considering the details of solving the problem, and to concentrate on how to solve the main contradictions, then, in the process of solving the problem, the details of the problem are divided into a small problem, and then the detailed problem is solved. A software that makes rational use of object-oriented technology for design and architecture is even more artistic in mind.

For example, to send an ad mail, the ad mail list is stored in the database. If you use C for writing, you will generally think like this. Read the mail content first, connect to the database, fetch the mail address cyclically, and call the sendmail command of Qmail on the local machine to send the mail.

If we consider object-oriented methods, no code can be inserted into the main process. Suppose we design three classes:

One class is responsible for reading the database, obtaining the mail address, and calling the sendmail command of Qmail to send;

One class is to read the mail content, MIME encoded into HTML format, plus the mail header;

A main class reads parameters from the command, processes the command line parameters, and calls the e-mail class.

Divide a task into three modules for processing, and each class completes a module task.

After careful analysis, we will find that such a design is completely designed from the programmer's perspective of implementing program functions, or that the design class is self-improving, from the machine perspective to the real world perspective. Therefore, at the design stage, we have taken into account all the details of program programming implementation, and attempted to meet the real-world software requirements from the starting point of the underlying implementation program. This analysis method is actually not applicable to object-oriented programming languages, because if you use C language instead and encapsulate two C functions, it will be much easier to implement than Java/C ++, logic is also clear. The essence of Object-oriented thinking lies in the thinking of the problem starting from the human thinking habits in the real world. As long as we understand this, we understand the object-oriented thinking methods.

So how can we implement the object-oriented method?

For an email, there are three attributes: the mail header, the mail body, and the mail address. to send an email, you need to send the email using a method, you also need a method to list all email addresses. Therefore, the following design should be performed:

Junkmail

Attribute:

Head

Body

Address

Method:

Sendmail () // send an email

Listallmail () // column email address

This is enough.

If the traditional process-oriented programming is a process that conforms to the instructions for running machines, the object-oriented thinking method is a thought process that conforms to human problems in real life.

When analyzing and designing object-oriented software, remind yourself not to think about the implementation of program code as soon as possible, and leave the constraints of specific programming languages aside, focus on analyzing the business logic of the software we want to implement, analyzing the business processes of the software, and thinking about how to describe and implement the business of the software. After all, software is just a carrier, and business is what we really want to achieve.

During the design, we should not consider the implementation of specific programming languages too early. We must use abstract methods to express business logic with methods unrelated to specific implementations.

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.