Talking Technical (1)
------ Mustware
What is the component technology? What is the role of component technology? Why apply component technology? How to apply component technology? What do we know now? What should we do now? What can I do? When these problems are entangled in their hearts, maybe you also admit that if you have to learn a component technology, your code To understand component technology (component technology will be replaced later). So now ask yourself, how do you see the components? What is the component in your mind? It feels very well, maybe each programmed person has a contour concept, yes, the Windows platform has been used for more than ten years, how can I not listen to the component? In terms of big aspect, when the MS is applying OL, the component is slowly developed, from the original OLE to CM to CMO even to the current .NET, there is no need to exist, but this is just Impact of a contour, I think, first you should understand some basic concepts when you learn the components. And the ultimate goal of writing this article is to answer the beginning of several questions and teach you how to write components (this article will write an OCX component, apply the MTS component, COM components, and for COM is the update version of MTS Some disambiguations exist will also be explained.
What is the component technology? The concept of the specific dead plate has a lot of definitions in various books. Component technology is to use some kind of programming means, and some people care, but not in the details of the end user to go directly to the direct operation, while The business logic rules are implemented, and the internal operation details of the user are handled, and even the security mechanism and the transaction mechanism are forth. This package is often called components. Perhaps this definition is somewhat reluctant, but this explanation is helpful to now, and this package is only acting as a simple tool, there is no practical meaning, that is to say to complete a certain One rule package can be done with tools written by any support component, and the final completed component is no relationship with the language itself, and even cross-platform. For us, it is to achieve some functions, there is a black box with input and output interface.
What is the role of components? This problem seems to have a little general, try thinking about how to achieve such powerful productivity? What is it in the back of it? One sentence: The component is the soul of Windows. The Windows system will no longer rush as the sky today. Windows is the same, and UNIX is the same. As an operating system, the function it complete does not raise components Service, a very easy copy - Paster is supported by DDE, and DDE is a component service object, and the specific to a detail, what is the big ERP rely on? What is the multi-layer system rely on? Component! Components encapsulate various rules of the system or even run the environment, and what is the completion of such services? This has to lift the component object. The so-called component object is a collection of components, and this collection is not a combination of random, and must take into account the coordination function of each component in the component object, although, in theory, The various components in a component object should be mutual interference, not affecting each other, but this does not mean that the component object is a collection of uncoordinated components. We must understand that by accessing a component in a component object, It is possible to access additional components in this component object to this loop. Who is managed? It is definitely a component object, which can be understood: Components have their own rules, and the implementation of the rules has been fed into the implementation of the interface, but the component object itself is also a component. It also has a business logic rule to handle it. It also Coordination of the collected components. As a result, you can coordinate some, part of business logic rules over a component object! For applicants, it is not necessary to know, even meaningful. Why apply component technology? Perhaps you will say that we can also handle some simple or slightly complex business rules, indefinitely, non-denied, without denying, using the method of programming, as a regular processing such as components objects. However, if it is just because we say that component objects or components are consistent with our usual coding, then it is now clear that this is a very bad idea. The purpose of using component technology is to achieve various rules {to implement rules} you want to implement, and component objects will also consider a broader aspect, it can uniformly plan a large distributed system, reasonable Simple programming tools such as redundancy, security, balanced load ... The functions of simple programming means are unable to apply, this is a very important reason we want to apply components. Furthermore, the component object is not an ordinary executable, and it is not to die in it inside it. It can make its own upgrade and expand (premise: no large amount of more interface), and give a simple Example, when we find that a business logic rule is already very old, we have to replace it with new business logic rules, and this replacement process will populate the component for ordinary .dll files or .exe executable Differences of files. When we need to update, for component objects, in the most ideal case, the user can accept new component technology while accepting new component technology while doing uninteresses, and tried to execute a DLL file or an executable Can files achieve such an effect? the answer is negative. If you say that these reasons are not enough, I can give a lot of applications to illustrate the necessity of component applications, however, there are too many reasons, and there is no need to list, you can refer to other technical materials or in us. Operation in operation.
How to apply components? At this point, we have more concern to implement the components through programming means. In the beginning, it has been mentioned, and the components use some kind of programming means to encapsulate business rules, and also emphasize that the language is only here. It is a tool. But when you can complete a component, then it will be more clear for its application, and amazed. So how do I apply component technology? Component technology is a high group application part, which can be made from the underlying system of the system, which has been encapsulated by the obvious function we can feel. In this process, we are to write a good component object or component through tools you are familiar with. What do we know now? Although component technology belongs to advanced programming categories, as long as it is programming to implement {another technology is not possible? }, We can go to implement one component. And we already know the application, role of the component, and we should do it now is to familiarize with a development tool. The so-called workers must have a good thing, and must first have a tool that we have a tool. It is possible to enter the door of the component technology (please do not entangle the component technology is the language irrelevant and the expression of the language, how to be aware of the language is not to be implemented, isn't it?), Otherwise Even if it is more thoroughly related to component technology, it can only stand outside the door. So we know nowhere to be two points: components and tools we have mastered.
What do we do now? What can I do? There will be collapse without the cornerstone, and we don't have a solid foundation, then the components we have written will also be some garbage! Or do not form a toy. Perhaps you understand the component, and also understand the Framework design, but all this is based on the basis for its kernel, you can only say that this is a blank design because you will not be able to experience it. The design model will bring your components to bring quality leap, the components, and others, just like a good project manager needs a sensitive thinking and superb or quite good skills, otherwise, others Will only think that he is talking about his own ideas. So we should do now are the full understanding of the application of components, and the rules of the component themselves and our development weapons. This is what we should do and we can do now.
When we have a basic outline or a relatively clear impact on the components, the next step is to combine our tools and components. Each development tool has its own characteristics. Although the different languages can achieve certain features, even if the development tools used by people, we should be aware of this, at this time, we should realize this is Wrong, because the development tool has its own good disadvantages, it is what we should do (not everyone is going to abandon it), this is one, and we must know what technology Implementing more benefits, redundant, reliable, etc. In today, we are familiar with our development tools to penetrate the idea of object-oriented programming. Why do you want this? The .NET's Framework design mode gives us a big advice. A component is actually a project, a project, and implementing the project. The best way to implement the project is to fully utilize OOP ideas. Of course, if you can determine you The version of the versions is the final version, but it is nothing, nothing more than the complexity of the encoding system in this release. You can see that OOP programming has a great help for us write components. If you are not clear, you may wish to give a very simple example: through OOP, you can sufficient reselling degree, improve scalable degree. And a component will be used as a number of terminal applications, we must take into account many of its efficiency, scalability, etc. This is a process of mutual. So after this, I will first make a simple summary of OOP {OOP programming, so this is just simple lifting, saving n words}. Let object-oriented programming penetrate to our A implementation of the implementation.
{Because you want to design some examples, and the tool I am familiar is Delphi, so this will be used as an OOP object in Delphi}
The three major core contents of object-oriented ideas are packaged, inherited, and polymorphism. Then we analyze these three points, and some examples are reviewed.
Here I save the analysis class, the objects, the object, but it should be understood that the object, as an example, from a certain meaning or general, it is a pointer, of course, if someone must emphasize Delphi is a reference / object model, which is not an object pointer, I don't tell.
Package: Component objects To package components, and components should be encapsulated interface, and the final interface still needs to encapsulate the business logic rules they achieve, so the single-in-one from OOP, the component objects and OOP should have some kind. Unless the relationship. Package main packets in two aspects: class package, object package, specific details can be referred to related materials.
The package is a UI separation, why do I say this? It is mentioned that it is the easiest to think that it is the black box. Indeed, I also admit that the package is a black box-based implementation, and it is also a ratio of quite a metaphor, how to say? Since the package is also the same "interface", one is alive, one is stable, and the so-called life is the implementation method of the service rule handled inside. If you don't care, we can use any means To achieve its internal functions, you can make an arbitrary modification (where the arbitrary modification here is just to add "live".) But no matter how it is live, how to be free, it There is a final purpose, in order to achieve a stable "interface", the internal content can be changed, and the stable interface should not be more movable. Thus, this is the case, an interface, component, and component objects. Similarly, this package is a UI separation. Don't stubbornly think that the UI separation is to put user operation and logical rules in two "physical", the operation is the package, if so think I can only say that your OOP is not understanding. Here, an example is analyzed: TCUSTOMFORM = Class (TscrollingWIntrol)
Private
FactiveControl: TwinControl;
FfocusedControl: TwinControl;
Function GetMdichildren (i: integer): TForm;
Function getmonitor: TMonitor;
......
public
Constructor Create (Aowner: Tcomponent); OVERRIDE;
Procedure afterconstruction; Override;
......
END;
It is to explain that the private is the part we just say, and its internal can be made, but it must ensure that the final public public is stable. This is a packing of a package and an example of a UI operation. At the same time, we should also notice that it is because of encapsulation, so we ask us to do some work when considering the stability part. When a project is made into the application, we have no way to change these stable parts, because These parts are associated with the user, the user's operation is the operation of the urgent portion, if one is changed, the properties of a stable portion of a user is using, the consequence is the re-planning and development of the project. In summary: The package can be hidden to achieve the details, making the code modular and realizes the reuse of the code. I don't know if the package is elaborated? If you have any questions, you can contact me, welcome you to discuss with me.
Inheritance: The package hides the realization details, then inherit? Inheritance is to extend the existing modules (such as class, interface), and it also achieves the reuse of the code, which has emphasized in the package, and the package is clearly divided into "live". Part and stable implementation portions, and we also mentioned that after the implementation, the distribution should not be fade, especially when a project has been put into the application, the re-modification of the stable part will destroy the original original intention Further, it is possible to cause the entire system to become garbage. In the interface, the rays are more obvious, then how do we do if we don't have functions, modifications such as a module, and we do? Modify one of the interfaces? I can't do it, the modification interface is actually saying: I will no longer serve my users, because the interface is being applied to the interface, and other components may call this interface will no longer Use, think of this result? {Description: Objects can implement multiple interfaces, and one component can also contain multiple objects that implement the interface, while a component object is a collection of multiple components}. How to do? Waste this component object or project? So what should users do? The boss allows us to do this? It is certainly uncomfortable. At this time, it is inherited. If a method in interface A is changed (the method here is actually attribute!), At the same time, it is necessary to add another attribute. There are two ways to rewrite an interface, and the other is to inherit the interface A, let the interface B as the derived interface of interface A, which can implement the inheritance attributes in all interface A, while overriding a certain property and implementing another rule and adds its own method, attribute. And all of this is completely transparent for users, they don't know what you have done, and I don't know, it has been replaced by an interface (can I replace it? Note the use of AS in Delphi). Polymorphism: While understanding the packaging and inheritance, let us take a look at the multi-state, if you want to figure out the polymorphism, you will spend too much space, and now about polymorphism Among you, you can refer to some information for understanding, just simple descriptions: polymorphism is the least understanding of the three basic concepts in OOP, and also the most interesting part, we mentioned the package to hide the realization details, make the code Modular; inheritable can extend the existing code module (class); their purpose is for-code reuse. And the polymorphism is to achieve another purpose - the interface is reused! The nature of the polymorphism is to assign a pointer to the parent class (quote in OP, essentially a pointer), as long as this is, the polymorph is generated, because it is implemented "Metaphum".
In part
{
Also talk
Package, inherit, and polygraphs constitute the three basic cores, packages of OOP, inheritable before we have been introduced, and the polymorphism does not conduct a detailed introduction, which is added to complement the three topics of OOP to end. The piece of OOP. About polymorphisms have introduced in many information, and the introduction is very exciting, then let this article will come again.
First of all, say nonsense, in the following introduction, and examples, I will use Object Pascal as a tool for explanation, and polymorphism is substantially OOP, which is not a tool, it is a kind of belief. Although described here in Object Pascal, it can be expanded to any language. The collapse is correct, continue our topic.
What is multi-state? What is the essence of polymorphism? What is the relationship between polymorphism and packaging? What is its position in OO? What did you get to our work? This article describes these issues, understanding polymorphism, understanding polymorphism, and application polymorphism in the process of elaborating. What is multi-state? It seems that there is no unified definition to standardize polymorphism, may explain the polymorphism more appropriate in our own understanding, where we do not quote some terms to define, the initiator can also understand this way of this definition. : Polymorphism, as the name, it is a variety of forms, and this variety of forms have been specific and what places? It can be understood that we can use a contour object to describe the number of objects, as for us to describe the state of the object, is not important for me. Why do you want this? The polymorphism is to give us a mechanism, we are just a formal statement, definition, and specific implementation details We don't have to care here. Or the specific implementation details will be handed over to other things. The base class we declared is just a definition from a certain sense. Just like the interface, there is no implementation, saying it here, has to say the essence of polymorphism. The nature of the polymorphism is that the base class provides a series of virtual methods. If you try to implement this base class, it will be in this way. Polymorphism is a thinking method that is completed by the object and his sub-objects. The polymorphism is to allow you to set the parent object to a technique equal to one or more of his sub-objects, and the parent object can operate in different ways according to the characteristics of the child object to which it is currently assigned. For users, they are concerned with the virtual methods provided by the parent class that do not implement detail. If you don't care, we don't care, there is no need to care about the implementation details of the interface. What we care is just that the interface provides us to complete our function, but what kind of way of interface is implemented Different features we need are even a specific way multiple features are there. I don't know if this explanation makes everyone feel very blurred, and it is impossible to accept it very well. please watch the following part.
Talking about the polymorphism, we must first understand that for the polymorphology, its parent class provides a lot of virtual methods, so we have no way to implement this parent class directly, only through its derive class to overwrite the virtual The method, so this produces a polymorphism. We all know that a class can be inherited by multiple subclasses, while the method implemented by each subclass is not until, or according to their own characteristics, there is a difference in the implementation of a specific method because of the differences, But we can completely deviate these operations through the parent class. The call to the subclass of the method can be fully implemented by the base class. Thus, if this class class is not derived, then this class is completely unsatisfactory! Only it is derived by a child, then it is really existence. Where is this significance? Or do we make this meaning be focus on what means? This is why we need further into the polymorphism, as shown below:
TA = Class
Public
PROCEDURE A; Virtual;
PROCEDURE B; Virtual;
P 's.
END;
When we declare class TA, you can see it has three methods, and it also noticed that these three methods are completely virtual. If we try to instantiate this Ta, there will be no meaning, because we Unable to implement the various methods for us to provide us, or the compiler will not provide space / mechanisms to let us implement these virtual methods. It can only be raised its role only by covering these virtual methods through its subclass. The overlay is the definition of subclasses, and implements the basic class. Such as: TB = Class (TA)
Private
B_STR: STRING;
Public
Constructor Create (Value: string);
DEStructor destroy (); OVERRIDE;
{This is overwritten. When you can use Override? When he accumulates the corresponding method is virtual or dynamic, you can use override}.
PROCEDURE A; OVERRIDE;
Procedure B; Override;
Procedure C; Override;
END;
Tc = Class (TA)
Private
C_STR: STRING;
Public
Constructor Create (Value: string);
DEStructor destroy (); OVERRIDE;
PROCEDURE A; OVERRIDE;
Procedure B; Override;
Procedure C; Override;
END;
Here is an initiator or not paying attention to the concept of people who are often confused. Override and overload. The above is said, the overlay is the method of refining the virtual function of the parent class (what is the use of inheced means you really understand?). And overloading means that there are multiple symbols that are allowed to exist, and the parameter tables of these functions are different (may although the number of parameters is different, the parameter type is different, maybe both different). as follows:
Procedure OpenSQL (Sender: TadoQuery; SQLSTR: String); OVERLOAD;
{When repeated, return to false, otherwise return to true}
Function OpenSQL (SQLSTR: STRING): Boolean; Overload;
Function ifrepeat (TableName, FieldName, FieldValue: String; INTVALUE: Integer = 0): Boolean; Overload;
Function ifrepeate (TableName: String; FieldName, FieldValue:
Array of string: String; Overload;
It can be clearly seen that the code on the upper side is a process of subclass over the virtual method of the base class, and it is still not very clear that the polymorphism of the polymorphism, or the nature of the polymorphism has not been mentioned. It is not very clear that you may not understand in advanced binding, and will be explained below.
When we derive class TB and TC from abstract class TA, and subclasses also covers virtual methods of base classes, how do these methods now apply? What kind of form will we call these methods? This is the most focused moment of polymorphism. It is also the most reflective nature of the polymorphism. I have already instilled the essence of the polymorphism is to assign a pointer to the parent type of the pointer, as long as this The assignment has occurred, and the polymorph is generated because "upward mapping" is implemented. Why do you say this? Continue our instance, assume that their implementation is as follows:
{TC}
Procedure tc.a;
Begin
inherited;
{inherted means handling the corresponding message to his parent class, he does not belong to the category of our discussion}
ShowMessage ('TC' C_STR);
END;
......
{TB}
Procedure tb.a;
Begin
inherited;
ShowMessage ('TB' B_STR);
END;
......
Now we can call the subclass through the parent class, and this process is actually a "upstream" process, both: a pointer for the subclass type to the parent class type; we can define a global The process to verify that we are on the side:
Procedure Test (Const PA: TA);
Begin
PA.A;
{Please put your attention here, we said that Ta is a category class, which provides the method that is virtual, only if it is covered, it can be applied, then the processing here is correct ? The answer is sure, so, the polymorphism is flying here, and I also give the process of calls.
END;
Procedure TForm.ButtonClick (Sender: TOBJECT);
VAR
VTC: TC;
Begin
VTC: = tc.create ('polymorphic instance _vtc');
TEST (VTC);
VTC.free;
END;
{Can you understand this "up-to-shoot" mechanism? The VTC is a reference value (object pointer) for a subclass TC, which can be assigned to its base class TA, so, the pointer to the child class type is assigned to the parent class type, so the polymorphism is generated. ! ! ! }
The late binding or dynamic will be described again here: When the subclass redefines the virtual function of the parent class, the parent pointer is dynamic according to the different subclass pointers assigned to it (remember: Yes! The call belongs to the function of the subclass, such a function call is unable to determine (the address of the virtual function of the subclass of the subclass) is not available during the compilation period. Therefore, such a function address is binding in the run period (late state).
I think, at this time, you should understand the polymorphism, then we tell the polygon is the weight of the OOP, then what role is there? What is it necessary to give us an efficient leap? Is it just to complete some kind of implementation? Is it only as a concept? These are what we must think about after understanding the polymorphism. So however, how will we affect our efficiency. We know that the package can hide the implementation details, making the code modular; inherit can extend the existing code module (class); their purpose is for-code reuse. And the polymorphism is to achieve another purpose - the interface is reused!
If you haven't understood polymorphism, you may wish to refer to the example below.
On this issue, you can say this: cannons can fight birds, the fire can also fight birds, do you use that? I don't care whether the cannon is still a fire, I only know that they can fight birds! Birds like the dinosaur, I use a cannon (just an example, which is so big bird? What to play is a word for the sanner: kill them, what? He doesn't care), the bird I use the fire. The enemy comes to me and can fight the enemy. This is the ultimate interpretation of the dynamics and an interface reuse! There are many places I am a predecessor.
}
In the summary of OOP, I want to say that I have some views of my current programmers, or I have a review of my OOP ideas, I once confused, I always thought that Delphi did It is an excellent development tool, efficient, fast, easy to use ..., but in a long time, I don't know if I do a project, whether there is some OOP penetration when I write the code? There is a feeling, I seem to take off the controls, the encoding is just the interface design of which it is encoded, visualized, and the rich and diverse can be used to make me feel very uneasy. I don't know if I am just like a figure. Pull a picture from one place, and then only modify this picture, although this makes me a very good application for VCL components, I have never been joy, I have been very depressed, VCL just gave us Do these? So I am no longer crazy to buy a book used by the VCL component. Only when I contacted the interface programming and component technology, I found that I used to be a long time, even through my entire programming career, only the existing VCL provided in Delphi. In the use of components, it is ignored to think about the meaning of object-oriented ideas for Delphi's entire component architecture system. I also understood why my predecessors were saying "Delphi in poison programmer"; here, I sincerely hope that you should not stay in the use of VCL components, but should use object-oriented thoughts to understand Delphi's entire The meaning of the component architecture system. After understanding OOP, we explain the other knowledge points you have to have the components: interface, maybe as you just contact the interface, this is a bit boring, but you must give you an explanation that the interface mentioned here will Below 100% reference to component technology or component objects, because they are ultimately implementation, packaging!
Please pay attention to the next article.
Posted please indicate: dprogram