Parallel two-dimensional plane
Pouting (paradigm) is a programming pattern, such as a process, object-oriented, generic, generating type (GENERATIVE PROGRAMING).
Object-oriented (OO) and generic are the two silver bombs that are most concerned in the current programming method, but Frederick Phillips Brooks have long told us, no silver! [Note 1] I want to deal with the specific and frequent, and and evil people in the software design, and the experience of a large number of people and the current computer do not have wisdom. However, although object-oriented and generic is still not enough to make a lot of silver bombs, they still bring us a lot of new ideas, new solutions to software people. In actual software projects, they have also successfully proved themselves.
Note 1: What is the problem with the absolute perfect solution? This truth understands, but can be so popular like "Moon Myth" is 30 years, but also continue to sell well, can convince the problem like Brooks, the words are like the beads, and the technology is in skill. The beauty of humanities is a perfect combination, it is not so easy. However, I have been thinking that the translation is very difficult, the habits of language, the expression method is too big, although the Chinese version translation is very good (at least I am looking for dust, I still think is in the English taste is indispensable It is recommended to buy a British film printing at the same time, and enjoy the beauty of English.
Speaking of object-oriented, now no longer a new concept, although many people must say object-oriented, but truly know and flexibly use packaging, inherit, and polymorphism.
Object-oriented is a longitudinally vertical concept, which is a partition of the software elements in the Y-axis direction in the planar geometry. It maps the problems in the problem domain space to be resolved into one object (Object), then classify a variety of objects, abstract various types of relationships between types (Class or Type), and various types of relationships. The most general relationship is inheritance, and more advanced should be used to further score the relationship between objects and types between the objects, increase the extra indirect layer, package. Change, separation interface and implementation, thereby adopting more flexible, easier maintenance design.
Although inheritance is something we know the most known to object, but there is a very simple judgment: if an object-oriented software has used a lot and deep inheritance relationship, it is not doubt that it is a failure design. Inheritance is mainly used to eliminate IF-Else, Switch, implementation of the IF-Else, Switch, and implement a polymorphism, just for multiplexing code, which is very unwise, it just leaves more trouble to the future. . It is necessary to use a combination as much as possible instead of inheritance (the protection inheritance in C can be said to be a combination, not to call inheritance). To use inheritance, you must take into account the Liskov principle, very simple, the place where the parent type, the child type can be unimpeded, that is, all interfaces of the parent type (Interface 2], subtype Distinguished.
Note 2: There are also translation as an interface, but I prefer the interface. Interface also claims that it is a Protocol, so-called protocol, that is, a set of services provided in the computer network, and is implemented as a type of member function (or method) in the object-oriented object. The so-called object-oriented, package, inheritance, polymorphism, to understand, is not too difficult, I introduced a book, "Thinking in Java", the latest is the third edition. And it is also a good book to learn Java, you can use a week (7 days) to see a look, the basic Java language knowledge and object-oriented basic concept will be familiar with the heart. [Note 3]
Note 3: In the summer vacation last year (2002), I was at the time in order to apply for a part-time job, for two days (about 12 hours), I saw the second version of "Thinking in Java" in the computer. A more and a half, and all procedures are commissioned, it feels easy to get started. Just a pity due to the company's reasons, there is no way. At that time, my computer foundation is not very good. The self-study computer is still less than a year. I learned about 4 months of C and C (I learned C ), and I am not smart, so I I don't think you can read 3 times for 7 days. The English in this book is very shallow. It is basically nothing difficult. It is very clear that it is unfortunately to see what English language is beautiful. This is not as good as "Effective C " and "More Effective C ", but "the mythical "MAN-MONTH". But as a Java language into the door textbook is very good.
Object-Oriented Application and Research Currently, it has basically reached the limit it can reach. When the red star Java and C # only support object-oriented design paradigm (PARADIGM) [Note 4] The successful proof of the object-oriented infinite power, I feel that now IT media is like the Emperor's Jiangshan, and the expression method is not used to the object to the object, and the programmer has been implemented by many talents. But cut your suit is uncomfortable. For example, the implementation of "Crosscutting Concern" in the program is a very awkward, a new design parallel aspect, and is achieved in Aspectj. [Note 6]
Note 4: You will say: "STOP, you miss it, Java also has Generic Java, which also supports generic programming." But please pay attention to two points:
A. Generic Java is not from official support, at least it has not yet been able to dissolve into orthodox Java blood.
B. Generic Java's generic implementation is a wiping method, which is an object-oriented code, which is the object-oriented code, and finally compiled into a .class file. You can refer to "Programmer" magazine 2002.8-2002.9, Mr. Houjie 's "Development of Java Pan".
Note 5: "Who is the Le Pingya? Who is the unified dominate? Who is higher than the alone? High high, Zhu Jun looks like it, the river is beautiful. , Won the world! "-" Qin and Han Buildings ".
Note 6: Please refer to the "Programmer" 2002.11 AOP column.
AOP is a new design generic, I only have seen a few articles, I don't dare to express their opinions, interested readers can go to http://aosd.net to enjoy a foreign trip.
To retired, object-oriented programming languages support very rich, including Encapsulation, Class, Interface, Inheritance, Polymorphism, Aggregate, RTTI. The various concepts in the problem domain in real life have a good mapping in the dispensing space, so the specific program language is relaxed.
Unfortunately, it is like heaven, you can imagine, but you can't achieve it. Our space is not only one-dimensional, there are many problems with object-oriented vertical vertical Y-axis is a wooden embarrassment, even if it is also a legal method for violating common sense. For example, the implementation of the ADT (Abstrct Data Type). For details, such as stacks, it behaves a collection of functions (advanced, pop-up, pressing). It does not need to have a common base class (subject), which can be died from each other to death, but it must have a common base class in the object-oriented object, then Each presentation is inherited from this base class, how many different presents are available, how many classes are there. The following short code performance is clearer:
Class Stack
{
Void push ();
Void Pop ();
Stack top ();
// ......
}
Class IntStack: Public Stack
{
......
}
Class PlateStack: Public Stack
{
......
}
// Many different types of Stack classes.
However, almost all classes in Java are inherited from the Object Class, which separately implements a Stack class, which can press the various types of objects into the Stack. When the Object is removed, it is converted down to a specific class.
Sample code:
// java code
Stack s = new stack ();
S.push ("string");
String str = (string) S.TOP ();
This is based on loss efficiency and type safety.
In short, these two solutions are very distorted! If you can use Stack
At this time, it should be rounded to the late X-axis powder. STL in C is the outstanding achievement of this axis. Keep in mind that template is not a generic, just a generic in C adopts template. The template in STL has achieved various common algorithms and data structures, and guarantees efficient efficiency, more and more fast than yourself, it is very like this), the current C programmer is more than before. There are many happiness, no longer need to repeat the wheels over and over again.
However, in the floodnual age of generic design (this era can be said to have not ended yet), it is difficult to debug the code unusual use of generic technology. The software will always have a wrong, and the programmer can find bug as soon as possible, and correct it. Since generic techniques do not have long, and those subjective are far from being object-oriented, it is still not very mature now. The language itself lacks a lot of support to it. Some concepts in objects, INTERFACE (C uses ABC, Abstract Base Class to simulate), Instantiation, Implementation (Extends in Java, Inheritance In C ). Language Level has been well supported, so-called language-level support is: If your function parameter type does not match, for example, Signature is Void Fun (Classa A); you Call it like this
Classb B;
Fun (b);
The compiler will give you a very clear error "Conversion from` Classb 'to Type `Classa' Requested, Type is misatched."
However, corresponding to these concepts in objects, the generics also have some of the concepts. Below I use several academic terms in generics, corresponding to Interface is Concept, in the example below.
Template
Class stack;
Just like the FUN function quotes (argument) must comply with ClassA's Interface, T must meet a concept - assignableconcept. That is, the template type parameter T must be an object type that can be assigned (Assignable), you might weird, there is still something that is not assignable, some, intelligent pointers that have ownership transfer (Smart Pointer) It's not good, just a single smart pointer auto_ptr is like this. Concept can be said to be a category, T must meet the requirements of Concept.
The generic terminology corresponding to Instantiation is Model, instantiation is the specific class of Interface, which is a specific object (Object), and Model is a CONCEPT. For example, int, double, and string types are both LessthanComparableConcept, just like 100,200 is a type Int, 3.4, 2.6 is a type of Double Double, please feel good.
Corresponding to the importation is Finement (refine, refinement) [Note 7], for example, ForwardIterator, ForwardITerator and Randomiterator are its model, but the Randomiterator itself is also ForwardIterator, but can't, so, Randomiterator is a FINEMENT for ForwardIterator. .
Note 7: I always feel that this correspondence is not appropriate, but I can't think of a good corresponding name. In fact, Finement is equivalent to a deep level (deep class hierarch), close to the specific class of the underlying is the advancement of the upper class. For example, class: | --------------------- |
| ----------- A -------- |
| | |
| --------------------- |
|
/ | /
| --------------------- |
| ----------- B ----------
| | |
| --------------------- |
|
/ | /
| --------------------- |
| ----------- C -------- |
| | |
| --------------------- |
Class C is the refinement of Class B. I have always regretted that I really want to see Matthew H. Austern's famous "generic programming and STL", but I can't buy it before, now there is no rice in my hand, only to go to work, I heard that there are many generic theories. I don't know if there is any appropriate correspondence with FINEMENT.
However, it is, in the implementation of the compiler, for these concepts Concept, Model, FINEMENT does not have a corresponding inspection mechanism, that is, the language itself is lacking. So these concepts need to be maintained by the programmer itself. If the program is wrong due to these concept itself, the compiler will inemold: a certain function is not implemented, an identifier (Identifier) does not know, ... for finding a real mistake, sometimes even exhausting your energy. For example, the implementation of the Stable_Sort function in the algorithm implementation of GCC STL:
Template
Inline void
Stable_sort (_randomaccessiter __first, _randomaccessiter __last)
{...}
The Stable_Sort function requires two _randomaccessiter (random access iterators, such as typical array pointers), so it cannot be used to sort LIST. List is a Node_Based container (Container), that is, a node (node) string, its iterator concept is _BIDIRECTIONALITER (two-way iterator). So the std :: stable_sort () function cannot be sorted by List, but use:
Std :: List
... // Enrichment of LI
// Attempt to sort LI
Std :: stable_sort (li.begin (), li.end ()); // error, li.sort () should be used;
The compiler should errone with Concept Mismatch, and the older compiler cannot find this reason. In the famous B object-oriented ST library, Jeremy Siek implements a conceptcheck library http://www.b object-oriented St.Org/libs/concept_check/concept_check.htm, specifically for this type of error check, GCC STL is directly In this library, VC7.1 also implements a similar library, and now the error is more obvious [Note 8]. However, this type of Concept check should be checked by the language itself, and should not be taken from external forces (special libraries and large ugly macros), so generic design paradigm is not mature. Note 8: You need to seek STL-related errors to accurately position, you can refer to the Leor Zolman's Stlfilt error message filter http://www.bdsoft.com/t object-oriented LS / Stlfilt.html
But if it doesn't use it because it is not mature, it will never mature. Is it a step-oriented design? Moreover, the generic is a scheduling of the horizontal horizontal X-axis of the software element. Its potential power should be as large as the vertical portrait Y-axis, so even the Java, C # is also ready to join the generic support in the next version, even now. After all, the two feet are still more comfortable than a feet :)
Now the X-axis, the Y-axis has a complete European Miles (Euclid) plane. Is there a z-axis, even in addition to three-dimensional, there is N-dimensional, non-European geometry? Please forgive my dull and ignorance, these questions and thinking will leave you for your brave smart and imaginative readers.
postscript:
There is an article on 9CBS "Type -Oop and GP Core Concept" will be very clear for object-oriented and generic, interested readers can see http://www.9cbs.net/develop/read_article.asp? ID = 14824.
The first thing I want to use is Matrix (matrix, parent), which only needs to be all available (COLUMN). But I don't dare to say generic and object-oriented is the lines and columns in software Matrix. To find these two pearls, it is really not what I am. In the next article I want to talk about Trinity in C - About Copy CTOR, Assign, Destructor.
Wu Tong wrote in 2003.5.29
Recently modified 2003.6.16