1. JAVA programming ideology-getting started with objects

Source: Internet
Author: User

1. JAVA programming ideology-getting started with objects

Object entry

If I have learned JAVA and have not read the book JAVA programming ideology, I am sorry to say that I have learned JAVA. In view of this, to is busy, secretly reading this legendary ox book.

Object-Oriented Programming (OOP) is attractive in many aspects. It enables faster and cheaper development and maintenance. For analysis and design personnel, modeling becomes simpler and can generate clear and maintained design solutions.

These descriptions seem very attractive, but I still have no impression (at least till now ).

Everything has two sides. What is the bad side? To enjoy such a good treatment, of course, we need to make greater efforts. We need to put away the previous procedural thinking and adopt image thinking. In addition, the object design process is more challenging, especially when you create reusable objects.

The last point about the disadvantages is the design challenge. don't worry too much. In many cases, most of us do not need to design our own objects. It is important to use the objects already designed by existing experts to solve our own application problems. We must stand on the shoulders of giants, instead of repeating the wheel of invention, right? After all, life is short. But then again, if we need to look back at who we are standing on and how the wheel was invented, the development process of this idea is of great benefit to personal cultivation and accumulation of wisdom.

1. Abstraction

Some people say that the ultimate goal of a programming language is to provide an abstract method.

The assembly language is the abstraction of the basic machine; the FORTRAN and C are the abstraction of the Assembly.

LISP and APL summarize all problems into my I algorithm, and PROLOG summarizes all problems as decision chains. They all have their own killer solutions to a specific problem, but as long as they exceed the limit, they will become clumsy.

Object-Oriented Programming integrators have taken another step. The elements in the Problem Space and the objects in the solution space are called "objects ). (If you are a programmer, kiss it. Maybe you can't leave it in your life .) By adding a new object type, you can flexibly adjust it to work with specific problems. OOP describes the problem based on the problem, rather than based on the solution. Compared with objects in the real world, it also has something in common: they all have their own characteristics and behaviors.

JAVA also has a father called SmallTalk. It was also invented by Alan Kay. Let's take a look at the summary of the object-oriented programming method by the founders of JAVA:

LEverything is an object. You can think of an object as a new type of variable. It stores data but requires it to operate on itself. Theoretically, all conceptual components can be put forward from the problem to be solved, and then expressed as an object in the program.

LA program is a combination of a large number of objects. Through message transmission, each object knows what to do. To send a request to an object, you need to "send a message" to the object ". More specifically, you can think of a message as a call request, which calls a subroutine or function from the target object.

LEach object has its own storage space, which can accommodate other objects. Or, by encapsulating existing objects, you can create new objects. Therefore, although the object concept is very simple, the complexity of the program can be reached.

LEach object has a type. According to the syntax, each object is an "instance" of a "class ". Here, "Class" is a synonym for "Type. The most important feature of a class is "What messages can be sent to it ?".

LAll objects of the same class can receive the same message. This is actually a different meaning, and you will soon be able to understand it. Because an object of the type "Circle" also belongs to an object of the type "Shape", a Circle can fully receive Shape messages. This means that the program code can run the "shape" in a unified manner, so that it can automatically control all objects that conform to the "shape" description, including the "circle ". This feature is called the "alternative" of objects and is one of the most important concepts of OOP.

The five features are summarized as follows:Everything is an object. A program is a combination of objects. An object has its own storage space and a type. The same class object can accept the same message.

2. object interfaces

Class has its own general features and behaviors. Each object belongs to a specific class.

After the class is created, many objects are generated as needed. Process the object as an element to solve the problem. Here, we will face a major challenge in Object-Oriented Programming. How can we establish an ideal one-to-one or ing relationship between the actual problem and the actual problem modeling.

The request we send to an object is defined through its interface. The object type or class specifies its interface form. The equivalence or correspondence between types and interfaces is the basis of object-oriented programming.

For example, the lamp type:

The interface specifies which requests can be sent to a specific object. But there is some code in a certain place to meet the implementation, which is better than hidden data. Send a message to the object, and the object determines how to respond to the message.

There are two reasons to control access to members. 1. To prevent programmers from getting in touch with things they should not be exposed, users can operate interfaces without understanding the information. 2. Allow database designers to modify internal interfaces without affecting callers.

JAVA has three display keywords and one implicit keyword to set the class boundary: public, private, protected, and friendly. "Pulibc" means that subsequent definitions can be used by anyone ." Private "no one except yourself, the creator of the type, and the internal function member of that type can access subsequent definition information.

3. REUSE OF THE SOLUTION

What are you doing?

Notes on programming ideas ~~~ Okay. Continue.

After a class is created and tested, it is a useful unit of code. However, this repetitive solution is not easy. Let's ignore this design issue first.

With a class, the new class can be composed of any number and types of other objects. This is called an organization. It is also like a car containing an engine.

4. Inheritance

Will you go crazy if a new data type forces you to implement a data structure with roughly the same functions? Therefore, we need to inherit it, which is designed for this goal.

The inherited class has the same type and interface as the basic class. Of course, you can add functions to the inheritance class as needed.

4.1 improve basic classes

JAVA has the extends keyword, indicating that we want to "extend" the new function for the interface. To distinguish between new classes, you need to change the original function. Although the function interfaces used are not changed, the new version of the function has different performances.

4.2 equivalent to a similar relationship

Can an inherited class only improve functions of the original basic class? If it is true, it can only be improved. The Inheritance class and the basic class are interfaces of the same type. There is an equivalent relationship between the base class and the inherited class. If the circle inherits from the geometric shape, then "the circle is a geometric shape", you must be sure. Otherwise, you will be stuck in the misunderstanding of "White Horse". You can see that programming not only learns IT knowledge, you can also learn philosophy. (If we say "the geometric shape is the circle", we will be laughed ).

However, some inheritance classes do not only improve interfaces, but add new functions, so they are not equivalent, just similar.

4.3 interchange of multiple objects

Treat the objects of the category class as an object of the base class. In this way, you only need to write a single code, ignore the specific details of the type, and only deal with the basic class.

Example:

It has the following function inheritance:

There is such a function

Void doStuff (Shape s ){

S. erase ();

//...

S. draw ();

}

This function communicates with any Shape, independent of any specific type of objects that it wants to draw and erase.

There is no problem with using the following code:

Circle c = new Circle ();

Triangle t = new Triangle ();

Line l = new Line ();

DoStuff (c );

DoStuff (t );

DoStuff (l );

Because doStuff can send a message to Shape, and Circle can also accept it, the above function is OK.

As long as we know that it is a Shape, it must be able to operate the doStuff function. If we need to perform different operations based on the circle and triangle, isn't it very bad? Right?

4.3.1 dynamic binding

When a draw message is sent to an anonymous Shape, the operation is correct based on the actual link type of the Shape handle. When a message is sent to an object, if you do not know the specific type of the message, but the action is also correct, this situation is called Polymorphism ). dynamic binding is the method used to achieve polymorphism. The compiler and runtime systems are responsible for controlling all the details; we only need to know what will happen. In C ++, it seems that the keyword virtual is required for dynamic binding, but it is not required in JAVA. It is automatically executed.

4.3.2 abstract basic classes and interfaces

Basic Classes usually want to provide interfaces only for their own primitive classes, and do not want anyone else to create objects of the basic classes. This can be implemented by converting the class into an abstract keyword. After an abstract method is inherited, it must be implemented. Otherwise, the inherited class will become an abstract class.

5. Object creation and existing time

Objects can be created in a stack or static bucket, or in a memory pool.

5.1 collection and inheritance

Create an object in the memory pool. You do not know how many objects are needed unless you are running. In the object-oriented design, most problems are simple creation of another type of object. In this case, the collection can be used, which is also called a container. We do not need to know how many things are stored in a set. We only need to create a set, and we will be responsible for future work.

C ++ provides the standard template library (STL) form, JAVA also provides a set with its own standard library. A common set can satisfy most people's requirements. All sets provide corresponding read/write functions.

If you need to operate or compare a series of elements in the set, you need to use the continuous generator Iterator. Should it be called an Iterator ?? Let's use E-text. Iterator is an object that selects elements in the set and provides them to the users of the integrator. The Iterator set is abstracted into a simple sequence, allowing us to traverse that sequence without worrying about what the infrastructure is.

A collection is just a place to prevent objects from being stored. If it meets our needs, there is no need to worry about how it is implemented.

 

5.2 single structure

There is an ultimate basic class in JAVA called Object. All objects in a single structure have a common interface and eventually belong to the same type. However, C ++ does not guarantee that everything belongs to the same basic type.

All objects in a single structure can have certain functions. With a single structure, you can easily implement a garbage collector. Necessary support related to this can be installed in the base class, and the garbage collector can send appropriate messages to any objects in the system.

However, a single structure will impose some restrictions on programming and increase the annual compatibility between new programs and the original C code. Therefore, C ++ decided to abandon the single structure in that year, but JAVA is different. JAVA is a new thing and has no burdens. Therefore, it uses a single structure.

5.3 collection library and convenient collection

A collection is a tool used by our processes. It is necessary for any database and can be easily reused.

As mentioned above, a single structure means that everything is ultimately an object. Therefore, a collection containing objects can actually accommodate anything, which makes it easy to reuse it.

However, the style (Cast) has to be involved here. How can we program this Object type to the type we actually put? It is a conversion from normal to special. There are two types of shapes: plastic and plastic. The type is changed from special to normal. For example, Circle belongs to Shape, which is undoubtedly correct. The Shape belongs to the Circle, which is a bit inaccurate, because it may also be a Triangle.

In this case, you need to create a smart set to know the type of your container. You can use parameterized types, which are automatically customized by the compiler and can work with specific types. Parameterized type is an important component of C ++. This is because C ++ does not have a single structure. JAVA has not yet provided parameterized types. It is also because of the use of a single structure that seems clumsy. However, JAVA retains the generic keyword and can be used for future implementation.

5.4 clear dilemmas

Each object requires resources to survive, and the most obvious is the memory resources. If it is no longer in use, you must clear it to release these resources.

In JAVA, the garbage collector has taken into account the issue of memory release during design. The Garbage Collector knows when an object is no longer used and then automatically releases the memory space occupied by that object. Because JAVA objects are inherited from a single root class, all programming is much simpler than C ++. You only need to make a few choices to address the large number of obstacles existing in the customer service.

Everything has two sides. In C ++, you can create an object in the stack so that the object can be automatically cleared, but it does not have the flexibility to create the object as needed during running. Likewise, the garbage collector can automatically clean up the memory space, but it brings about a problem. During JAVA program execution, there will be an inconsistent factor, I can never determine when to start or how long it will take.

In addition, JAVA is simpler than C ++. In C ++ programming, C ++ will not be used if C can be used, so C ++ is obviously complicated. On the other hand, JAVA is simple, and the cost is the loss of efficiency and the flexibility of a certain program.

6. Violation Control

Error Control has always been a major problem that designers need to solve. Many languages simply ignore the problem and pass it on to the designer.

In violation control, the error control scheme is built into the programming language. The violation (Exception) is a special object and will be thrown out from the place where the error is generated.

In JAVA, the violation control module is encapsulated from the very beginning, so it must be used.

Violation control is not an object-oriented feature, although it is usually represented by an object in an object-oriented programming language. However, before the advent of object-oriented language, violation control already exists.

7 Multithreading

In computer programming, multiple tasks need to be controlled.

One of the most valuable features of Multithreading is that programmers don't have to worry about how many processors they actually use. The program is logically divided into several threads.

When processing multiple threads, you must pay attention to one problem: sharing resources. When you try to access a resource at the same time, you will encounter resource competition, which requires locking the resource.

JAVA's multithreading mechanism has been built into the language, making complex problems easy. JAVA supports multi-threaded processing at the object level. An execution thread can be expressed as an object.

8 permanent

Some objects will still be able to retain all information when they start the program next time, which is very valuable.

JAVA provides limited permanent support, which means we can simply save the object to the disk and retrieve it at any time. It is called limited because we still need to make a clear call to save and retrieve objects.

9 Java and Internet

JAVA not only solves traditional programming problems, but also solves Programming Problems on the World Wide Web.

9.1 C/S computing

The basic idea of the client/server system is that we can store information resources in a unified place. The key to Client/Server overview is that information is stored in a centralized manner. You can easily change the information and then distribute the modified information to the consumers. In the past, we generally adopted separate solutions for separate problems; each time we had to design a new solution. These solutions are difficult to create and use, and users must learn and adapt to the new interface each time. Client/Server problems need to be fundamentally changed!

9.2 Web Server

Web is actually a large-scale client/server system.

The user then hopes that a certain information can be displayed on any type of computer without any changes. At this time, the client itself is just a pure viewing program, not even a simple computing (of course, this avoids virus harassment)

The client capability is too weak, and people have to program the client.

9.3 client Programming

The "server-Browser" solution provides interactive content, but this interaction capability is completely provided by the server, which brings a lot of burden to the server and the Internet. The server generally generates static Web pages for the client browser, which are simply explained and displayed by the latter. The information submitted by the user is returned to the server through the Common Gateway Interface (CGI) supported by all Web servers.

Many Web sites are strictly built on CGI. In fact, almost everything can be done using CGI. The only problem is the response time. The response of the CGI program depends on the amount of data to be transmitted, and the load on the server and the Internet is multiple.

We press the Submit button on the web page (Submit); the data is returned to the server; the server starts a CGI program to check whether user input is wrong; format an HTML page to notify possible errors, and return this page to us; then you must return to the original table single page and enter it again. This method is not only slow but also cumbersome.

The solution is to design the client program.. Most machines running Web browsers have strong enough capabilities to do a lot of other work. Client programming means that Web browsers can be fully utilized and effectively improve the interaction (interaction) capability of Web servers. The discussion of client programming is not much different from that of conventional programming. The parameters used must be the same, but the operating platform is different: the Web browser is like a limited operating system.

9.3.1 plug-in

One problem of client editing is the design of plug-ins. Plug-ins allow you to easily add new features to your browser. The purpose of the code is to tell the browser that "from now on, you can perform these new activities ". However, writing plug-ins is not a simple task.

You do not want to work in this area when building a specific site. For client program design, the value of the plug-in is that it allows professional programmers to design a new language and add that language to the browser without the permission of the browser creator. It can be seen that the plug-in is actually a "backdoor" of the browser, allowing the creation of new client programming languages (although not all languages are implemented as plug-ins ).

9.3.2 scripting language

The plug-in causes explosive growth of the script language. With this scripting language, you can directly Insert the source code for your client program to an HTML page, and the plug-in that language will be automatically activated when the HTML page is displayed.

All scripting code is exposed to people.

The scripting language is designed to address specific types of problems. It mainly involves creating a richer and more interactive GUI ).

Because the purpose of the scripting language is to simplify and speed up as much as possible, before considering other more complex solutions (such as Java and ActiveX), you should first consider whether the scripting language is feasible. Currently, the most discussed scripting languages include JavaScript, VBScript, and Tcl/Tk.

JavaScript may be commonly used, and it provides the most comprehensive support. Many browsers currently support JavaScript. Some tools can also use JavaScript to automatically generate Web pages.

9.3.3JAVA

If a scripting language can solve 80% of client programming problems, what should we do for the remaining 20%? Currently, Java is the most popular solution. A powerful, highly secure, cross-platform, and international programming language is also a vigorous language.

Java is constantly extended. The language features and libraries provided can solve the problems that traditional languages cannot solve, for example, multi-threaded operations, database access, network connection programming, and distributed computing.

Java uses the "Program chip" (Applet) to cleverly solve the client programming problem. A Program (or a "small application") is a very small program that can only be run in a Web browser. As part of a web page, the program piece code will be automatically downloaded (similar to the picture on the page ).

After activating the program chip, it will execute a program. One advantage of a program piece is that the software can be automatically downloaded from the server once the user needs the customer's software. They can automatically obtain the latest version of the customer's software, without errors or re-installation troubles. Due to the design principle of Java, programmers only need to create a version of the program, which can run in almost all computers and browsers with the Java interpreter installed.

Compared with the script program, another advantage of the Java program is that it adopts the compiled form, so the client cannot see the source code. On the other hand, decompiling Java program slices is not difficult, and code hiding is generally not an important issue. You should pay attention to the other two important issues.

9.3.4ActiveX

To some extent, a strong competitor of Java should be Microsoft's ActiveX, although it uses a completely different set of implementation mechanisms. ActiveX was originally a pure Windows solution. Through the efforts of an independent professional association, ActiveX is now capable of cross-platform use. ActiveX means "If your program is normally connected to its working environment, it can enter the web page and run in a browser that supports ActiveX. ActiveX does not limit the use of a specific language. If we are a Windows programmer and can skillfully use languages like C ++, Visual Basic, or BorlandDelphi, we can create ActiveX components without any learning.

9.3.5 Security

Automatically downloading and running programs over the Internet is a dream of virus makers. ActiveX brings the biggest headache in client programming. When you click a Web site, it may send back any number of items along with the HTML webpage: GIF files, script code, compiled Java code, and ActiveX components. Some are harmless; GIF files do not cause any harm to us, and the scripting language usually has a lot of restrictions on what you can do. Java is also designed to run in a secure "sandbox" in its program, which prevents operations from being performed on disks or memory areas outside the sandbox.

ActiveX is the most worrying of all. Compiling a program with ActiveX is like compiling a Windows application-you can do whatever you want. After downloading an ActiveX component, it may completely damage the files on our disk. Of course, for those programs that are downloaded and not limited to running inside the Web browser, they may also damage our system. The virus downloaded from BBS has always been a big problem, but the speed of the Internet makes the problem more complicated.

The current solution is "Digital Signature", and the code will be verified by an authority to show who the author is. This mechanism is based on the assumption that the virus is transmitted because its creator is anonymous. Therefore, if the anonymity factor is removed, all designers have to take responsibility for their actions. This seems to be a good idea because it makes the program look more formal.

Java uses the "sandbox" to prevent these problems. The Java interpreter is embedded in our local Web browser. When the program is loaded, all suspicious commands are checked. In particular, program films do not have the right to write files into a disk or delete files (this is one of the virus's favorite tasks ).

9.3.6 Internet and Intranet

Web is a common solution for solving client/server problems. Traditional Client/Server models face different types of customer computers, and it is difficult to install new customer software. However, through Web browser and client programming, these two types of problems can be well solved.

If an information network is limited to a specific company, after applying Web technology to it, it can be called an "Intranet" to show that it is an international "Internet) yes. The Intranet provides a higher level of security than the Internet, because it can physically control the use of internal servers within the company.

Security issues introduce us to a branch that seems to be automatically formed in the client programming field. If a program runs on the internet, you should pay special attention to programming to prevent possible programming errors because you have no idea on which platform it will run.

When faced with a series of confusing solutions for client programming problems, the best solution is to first perform an investment/return analysis. Summarize all the constraints of the problem and what is the fastest solution. Because the client program design still needs to be programmed, you should take the best development path for your specific situation in any case.

9.4 Server programming

Traditionally, server-side programming uses Perl and CGI scripts, but more complex systems have emerged. This includes a Java-based Web server, which allows us to program all the servers in Java. The program written is called a "small service program" (Servlet ).

9.5 applications

Java is actually a general-purpose programming language that can solve any type of problems, at least theoretically. Turning the line of sight from the program film (and relaxing some restrictions, such as prohibiting Disk Writing) has entered a broad field of applications for general purposes. This type of application can run independently without a browser, just like a normal execution program.

Here, Java features are not only reflected in its porting capabilities, but also in programming itself. As mentioned throughout the book, Java provides many useful features that allow us to create programs that are more robust than the previous programming language in a short period of time. However, we have to pay some price. The most obvious one is that the execution speed has slowed down (although many adjustments can be made ). Java itself also has some limitations, making it not very suitable for solving some special programming problems. Java is a rapidly developing language. With the release of each new version, more and more problems can be solved.

9.6 Analysis and Design

The object-oriented paradigm is a new and totally different way of thinking about programming. In fact, we can make a "good" design, which can take full advantage of all the advantages provided by OOP.

All objective of OOP is to make the software development process easier.

Most methods are designed to solve the maximum problem. There are some particularly difficult projects that require more effort. However, most projects are relatively "conventional", so successful analysis and design can generally be achieved, and only a small part of the recommended method is needed.

No matter how limited, some forms of processing are always beneficial, which makes the development of the entire project easier and better than coding directly!

Remind yourself to pay attention to the following issues:

(1) What is an object? (How to split your project into a series of independent components ?)

(2) What are their interfaces? (What messages need to be sent to every object ?)

After determining the objects and their interfaces, you can start to write a program. For many reasons, more instructions and documents may be required, but the required information must not be less.

The entire process can be divided into four stages, as described below.

9.6.1 stage 0

The first step is to determine the steps to be taken in the subsequent process. If the plan is to "start coding directly", then of course it is beyond reproach (if you have a thorough understanding of the problem you want to solve, you can consider doing so ). However, at the minimum, you should agree that you should have a plan.

Some programmers prefer to do what they like when writing programs. They think that "it will be done naturally ". This may not be a problem at the beginning, but I think it would be better for you to concentrate if you can set a few signs or "road signs" throughout the process. After achieving one goal after another, you can have a clear grasp of your progress.

9.6.2 Stage 1 prepare a plan

In the process, this stage is called "establishing requirement analysis and system specifications ". Requirement analysis refers to "Creating a series of rules based on which to determine when the task is completed and how the customer is satisfied ".

The system specification indicates "Here are some specific instructions to let you know what the program needs to do (rather than how to do it) to meet the requirements ". Demand Analysis is actually a contract between you and the customer (even if the customer works within the company, or other objects and systems ).

The system specification is the highest level of exposure to the problems we face. We determine whether the task is completed and how long it takes. Since all of these require the consistent consent of the participants, it is best to simplify them as much as possible, in the form of a list and basic charts to save time.

We should pay special attention to the core issues at this stage and not to be entangled in details. The core issue is: determine the system to use. The most valuable tool for this problem is a set of conditions for use. For those ......, What should the system do ?" This is the most convincing answer to formal questions.

Summarize the complete set of "usage conditions" or "application scenarios" of your system as much as possible ". Once this task is completed, it is equivalent to figuring out the core tasks that the system wants to complete. Since we focus on "Conditions of use", a good result is that they always let you focus on the most critical things, and prevent yourself from being distracted from other things that do not have much to do with task completion. As long as you have mastered a complete set of "usage conditions", you can clearly describe your system and move it to the next stage.

Use a few simple paragraphs to describe your system, and then expand around them to add some "Nouns" and "verbs ". "Nouns" naturally become objects, while "verbs" naturally become "methods" to be integrated into object interfaces ". As long as you try to do it yourself, you will find out how useful a tool is. Sometimes, it can help you do most of the work.

Although it is still in its infancy, some schedules may be very useful at this time. We now have a comprehensive understanding of what we want to build, so we may have realized how long it will take to complete. There are many factors to consider: if a long schedule is estimated, the company may decide not to continue; or a supervisor has estimated how long the project will take, and will try to influence your estimation. However, in any case, it is best to draft a "Honest" timetable from the very beginning and make other decisions that are currently difficult to make. There are many technologies that can help us calculate accurate schedules (like those that predict the stock market ), but usually the best way is to rely on your own experience and intuition (don't forget, intuition should also be based on experience ). How long will it take, and double the time, plus 10%. You may feel correct; "maybe" can be done at that time. But "double" makes that time more abundant, and "10%" is used for the final scrutiny and deepening. But at the same time, I also need to give an appropriate explanation to the Superior Supervisor. No matter what complaints or changes the other party has, just tell them clearly that such a schedule is just my estimation!

9.6.3 Stage 2 Design Plan

At this stage, we must come up with a set of design schemes and explain what the various objects are like in appearance and how they communicate with each other. In this case, you can consider using a special Chart Tool: "Unified Modeling Language" (UML ). Of course, you don't have to use UML, but it will be very helpful to you, especially when you want to plot a detailed chart so that many people can study it together. In addition to UML, you can also choose to provide a textual description of objects and their interfaces.

The most wonderful thing in this process is that the entire group did not learn some abstract examples for object-oriented design, but learned the tricks of OOP by practicing a real design, that design is exactly what they were working on! After the objects and their interfaces are described, the 2nd stage is completed. Of course, these jobs may not be complete. Some work may not be available until it enters Stage 3. But this is enough. What we really need to care about is to eventually find all objects. Early discoveries are certainly good, But OOP provides a perfect enough structure to find them later.

9.6.4 Stage 3 Creation implementation

The correct design structure is mastered before the formal coding, so it is much easier to continue with the subsequent work than to write a program at the beginning. This is what we want to achieve. Let the code do what we want to do. This is the final goal of all Program projects. However, do not rush in; otherwise, only the loss is worth the candle. Based on my experience, I finally come up with a comprehensive solution to make it as thoughtful as possible to meet as many requirements as possible.

Programming is more like an art. It cannot be viewed as a technical activity. All contributions will eventually be rewarded. As a real programmer, this is not a dispensable quality. Comprehensive Thinking, careful preparation, and good construction not only make the program easier to build and debug, but also make it easier to understand and maintain, and that is the necessary condition for a set of software to make profits.

After the system is built and run, it must be tested. The previous requirement analysis and system specifications can be used.

Fully examine your own procedures and determine that all the requirements have been met.

9.6.5 Stage 4 maintenance or revision

The entire development cycle is not over yet. Now we are entering a stage that is traditionally called "maintenance. "Maintenance" means "Keeping it running on the expected track", "adding a customer to a previously forgotten declared function", or "getting rid of all the bugs exposed" in a more traditional way.

People have many misunderstandings about the word "maintenance". Some people think that anything that requires "maintenance" must be good or defective! This word indicates that you are actually building a very "primitive" program. In the future, you need to make frequent changes, add new code, or prevent it from falling behind or degrading. Therefore, we need to use a more reasonable term to address the work that needs to be continued in the future.

This word is "revision ". "What we did for the first time is not perfect, so we need to leave a space for deep learning and cognition for ourselves, and then let us go back and make some changes ". As you learn and understand the problem, you may need to make a lot of changes. One of the driving force behind these jobs is the constant reform and optimization that can finally get a return from your own efforts, whether it needs to go through a short or long period of time.

Due to various reasons, future changes to the program are essential. However, you must confirm that the changes can be easily and clearly implemented. You need to understand not only what you build, but also how the program evolves constantly.

Object-Oriented programming languages are especially suitable for making such continuous changes-the boundaries established by objects can effectively ensure the integrity of the structure, it can prevent unnecessary interference and damage to irrelevant objects. You can also make some seemingly drastic changes to your program without compromising the program integrity and affecting other code. In fact, the support for "revision" is a very important feature of OOP.

Through revision, you can create things that are at least close to your own ideas. Then, observe your work as a whole and compare it with your own requirements to see what is in short supply. Then you can easily go back and redesign and implement the inappropriate parts of the program.

Before you finally get an appropriate solution, you may need to solve some unavoidable problems, or at least one aspect of solving the problem. It usually takes several more revisions.

Repeated "revisions" are closely related to "incremental development. Incremental development means starting from the core of the system and implementing it as a framework. Later, we will establish the remaining parts of the system on the basis of this framework. Then, the various functions (features) to be provided will be added one by one.

At this time, we should focus on building a simple and clear version so that we can have a clear grasp of the system. Then, we threw out the prototype and constructed it formally. One of the most troublesome scenarios for quick styling is that people do not drop the prototype, but build it directly on the basis of it. Coupled with the lack of "structures" in the programmatic design, it will lead to a chaotic system, resulting in increased maintenance costs.

 

9.6.6 plan return

If you have not carefully drawn up the design drawing, of course, you cannot build a house. For example, if a dog house is built, although the design drawing does not need to be so detailed, some sketches are still needed to be well understood.

Software development is completely different, and its "design diagram" (Plan) must be detailed and complete. For a long period of time, people did not have much structure in their development process, but those large projects could easily fail. Through constant exploration, people have mastered a large number of structures and detailed information. However, they are used to make people worry-it seems that they need to spend most of their time writing documents, rather than programming much time (this is often the case ). You need to adopt a method that best suits your needs (and habits. No matter how small a plan is, some form of plan will greatly improve your project compared to no plan at all.

Please remember: according to estimates, more than 50% of projects that are not planned will fail!

 

9.7 JAVA and C ++

Java is especially like C ++. Therefore, it is natural to come to the conclusion that C ++ seems to be replaced by Java.

In any case, C ++ still has some features that are not available in Java. And despite a lot of guarantees, it is claimed that Java will reach or exceed the speed of C ++ one day. However, this breakthrough has not been implemented so far (although the speed of Java is indeed improving steadily, it still does not reach the speed of C ++ ). In addition, many C ++ enthusiasts exist in many fields, so I don't think that language will soon be replaced by another language (the power of enthusiasts is negligible.

The power of Java is reflected in a slightly different field from that of C ++. C ++ is a language that never tries to cater to a certain model. In particular, its form can be varied to solve different types of problems. This is mainly reflected in tools like Microsoft Visual C ++ and Borland C ++ Builder.

They combine libraries, component models, and code generation tools to develop Windows end-user applications (for Microsoft Windows operating systems ). On the other hand, what are the most common features of Windows developers? Is Microsoft's Visual Basic (VB ). From the perspective of language design, although VB is so successful and popular, there are still many shortcomings. It is best to have the powerful functions and ease of use like VB at the same time, and do not generate code that is difficult to manage. This is exactly the most attractive part of Java: as the "next-generation VB ". People have done a lot of work on Java, enabling programmers to solve application-level problems (such as network connection and cross-platform UI ), therefore, it allows people to create very large and flexible Code subjects in essence. At the same time, considering that Java also has the most "robust" type check and error control system that I have not seen in any other language so far, therefore, Java can greatly improve our programming efficiency.

But can I change C ++ to Java without thinking about a specific project? In addition to Web application films, there are two issues to consider. First, if you want to use a large number of existing libraries (which can certainly improve the efficiency), or if you already have a solid C or C ++ code library, after replacing it with Java, the reflection will hinder the development progress, rather than speeding up its speed. However, if you want to build all your code from the beginning, Java's simplicity and ease of use can effectively shorten the development time.

The biggest problem is speed. In the original Java interpreter, the Java interpreted will be 20 to 50 times slower than C. Despite a long period of development, this speed has been improved to a certain extent, but it is still very different from C. The most important thing about a computer is speed. If it cannot work significantly faster on a computer, it would be better to do it by hand (someone suggested using Java during development to shorten the development time. Then, use a tool and support library to convert the code into C ++, so that faster execution can be achieved ).

To make Java suitable for most Web development projects, the key lies in the speed improvement. In this case, we need to use a compiler called "Just-in-time" (Just-InTime, or JIT), or even a lower-level code compiler. Of course, the low-level code compiler will make the compiled program not run across platforms, but it also improves the speed. This speed is even close to C and C ++. In addition, cross-Compilation of programs in Java should be much simpler than that in C and C ++ (in theory, only re-compilation is required, but it is still difficult to implement; other languages have also made similar guarantees ).

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.