How to build a flexible system with Scalability

Source: Internet
Author: User

References:

Design Pattern-Basis for reusable Object-Oriented Software

Object Design: roles, responsibilities, and collaborations

Http://en.wikipedia.org/wiki/Extensibility

 


From my understanding, in the software field, it is the property of the software system, or, further, the property of the design and the property of the Code. Because we often talk about design scalability and code scalability. That corresponds
What is it? It is a change. Changes in the software environment (which may be the business environment or runtime environment) lead to changes in the software to meet people's requirements. The ability of the system to adapt to changes is scalability.

First, let's take a look at several forms of system expansion:

 

1) directly modify the code.


I believe everyone has had this experience when demand changes or new demands increase. We may modify multiple class files, which may also involve configuration files and front-end page files. This change must be re-edited.
Translation: Packaging and deployment must be stopped. This change involves a wide area and requires careful analysis in advance. After the change, a regression test with a large area is required to ensure that the modification will not introduce new problems.

 

2) directly modify the code, but only limited to one class or method.

Although this type of code is also directly modified, the scope of the change is limited, and the impact on other parts of the system is not that big, so it is relatively easy to analyze. The scope of regression testing is also smaller than the above practice. You still need to re-compile, package, and deploy it.

 

3) Use inheritance to write the classes inherited by sub-classes, and add new business logic to the sub-classes.

In this way, no previous business logic code is modified, but a new class is added to accommodate the new business logic. However, you also need to modify some code when linking a new class to the code. For example, the instantiation process of the new class requires static compilation links.

 

Java code
  1. Classa {
  2. Void dosomething ();
  3. }
  4. ......
  5. Classa A = new classa ();
  6. ......
  7. Classb extends classa {
  8. Void dosomething ();
  9. Void addedmethod ();
  10. }
  11. ......
  12. Classa A = new classb ();
  13. ......
ClassA{     void doSomething();}......ClassA a = new ClassA();......ClassB extends ClassA{   void doSomething();   void addedMethod();}......ClassA a = new ClassB();......

 

Some people say that the factory method is not good, simple factory is not good, and factorymethod is not good, so it cannot eliminate the code of the new class for instance.

 

4) object Assembly during running.
Next, you may think that the class instantiation logic is moved to the runtime for assembly through reflection, which indeed solves 3rd) problems. Spring is mainly engaged in these tasks. At this time, the principle of opening and closing is truly met.
Spring provides us with a very flexible and scalable basic technical architecture. For more information, see Martin Fowler about dependency injection.
.

 

5) module-based Dynamic Scaling during runtime.
So far, we have discussed more fine-grained technical extensions. Imagine that if you add some functions, You can inherit all kinds of classes and complete a function only after complicated assembly process.
. Even if you add a new class, modify the spring configuration file, and implement new assembly, you still need to compile the entire project. That is to say, the first four did not reach the module level.
.
Osgi provides a solution to achieve dynamic module-level Scaling and runtime. The so-called dynamic extension of runtime modules. For example, if you need to add some new functions, you can organize newly developed classes and files according to bundle and then directly throw them to the runtime environment, these functions can be used.

The Eclipse plug-in architecture is built with equinox (an osgi standard implementation) as the core. It mentions the concept of extension/extension points, which is far more flexible than the previous four solutions, and achieves separation of focus compared with 4. For example:

 

For example, I have developed a file upload function. The file type and address can be dynamically expanded.

Spring Processing Method:
You can flexibly configure the upload type and upload address in bean configuration. You must modify the configuration file for each added address or file type. What's more terrible is that Michael Jacob developed this file upload module and developed other
To use this function, module Li Si needs to communicate with Michael Jacob, either modify the configuration file or request Michael to add his own file upload path. This complexity increases when the system scale increases and the number of changes
It is almost unmanageable and requires a huge cost.

 

Eclipse implementation method: Zhang San developed a file upload plug-in, which exposes two extension points, one of which is the file type and the other is the file upload address.

Li Si didn't even have to say hello to Zhang San. He developed two extensions and registered them on the extension points. Michael Jacob collects extensions during runtime and processes them. Separated functional usage and functional definition concerns. You only need to abide by the expansion contract.

 

6) based on the intermediate language.
The framework usually defines some hot spots, which can be expanded. Platform with the strongest scalability, such as window
Platform, you can develop applications to run on it. Windows provides thousands of APIs that you can use to develop applications. We are looking at Firefox. He can insert
To expand. We often use extensions, also known as extension, which can be developed through XUL, XBL, JavaScript, and CSS. In terms of thinking, he and
The same is true for Windows, which is extended by some special language in the middle, but Windows supports a little more languages. It is inferred that, technically
The maximum scalability is achieved through one or more intermediate languages. For example, the popular opensocial
Both API and Facebook use this idea. In this way, the emergence of DSL is just a matter of course, it is designed to meet the needs of expansion in a certain business field. The idea is the same as previously mentioned.
To put it bluntly, it is the order, the choice and the loop can express all the logic. This is proved, and this is the essence of language flexibility.

 

So far, this should be the most flexible way at the technical level. But how do I divide modules? Big or small? How to Control dependencies between them? Why define this extension point?

This raises another question,"Why are we scaling ?"

 


Expansion is purposeful. We cannot blindly expand for expansion and make the system extremely complex to deal with almost impossible changes. Let's talk about design again. Traditional software development process focuses on big
Front
Design is a lot of preliminary design. One practice of XP is simple design. I highly recommend simple design, that is, just the right design. Not much or much, just like pork, fat but not greasy. How to do this
Depends on the experience of the designer.

 


To answer this question, it is important to know how far we can see and how many possible changes can be predicted. These are the basis. The other is your understanding of the context, which requires additional knowledge. More contextual knowledge
Rich, the more clearly the relationship between them, the more likely it will be to identify possible system changes. When designing the system, we can prepare some slots for these changes and design some expansion points.Scalability is designed.

 

I don't know exactly how to grasp this aspect, context-special.

 

Summary:

 

1) in order to control the complexity, the system must be logically divided. The logical blocks should be loosely coupled and need to be understood and carefully analyzed in the field.

2) scalability is not achieved overnight. It needs to be reconstructed with your in-depth understanding of the business field. Generally, three times can reach an ideal level.

3) In the process of system evolution, we are always ready to pay attention to complexity. Make sure that these complexities are digested.

4) To achieve scalability, you need to have a better understanding of the context.

 

People have no worries.

 

The same is true for systems.

 

 

From: http://gurudk.javaeye.com/blog/326496

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.