Object-oriented programming method of: cold summer

zhaozj2021-02-16  49

Object-oriented programming method of: cold summer

In the mid-1960s, the object-based language was born, and the object-based programming was opened up new "audio-visual" space compared to the previous traditional programming method, and the object-based programming introduced different processes. Concepts and terms; how to use object-based programming methods to achieve rule set in the firewall ...

In the mid-1960s, the object-based language was born, and the object-based programming was opened up new "audio-visual" space compared to the previous traditional programming method, and the object-based programming introduced different processes. The following concepts and terms:

1. Objects, objects in the object, is the concept of the object of the object, is an instantiation of the class, which simulates the specific existing objects in the real world, with its own attributes and similar objects. Commonity). The role of the property is: communication with other objects, manifested as a feature call; reflects its own state change, representing the current attribute value. Therefore, it is static, and the object can be represented as (interface, data, operation), dynamic, and the object can be represented as an automatic machine having an input output function.

2, class, is a static concept in the object-based program, which is an abstraction of a group with a common property in the objective world, and the class is provided is an object-instantian template. It includes the commonality of this group, During the operation of the program, the class only works in an instantiated object. The concept of classes is the basic concept of object-based programming and is a facility that supports modular design.

3, inheritance, reflecting the difference in abstract levels between classes and classes, depending on the relationship between inheritance and inheritance, can be divided into derivatives and base classes, the base class is also known as the parent class, the derivation is also referred to as subclasses As the word "inheritance" gives us literal prompts, the subclasses will get all the properties and methods from the parent class, and can be transformed into these attributes and methods to make them their own characteristics. A parent class can derive a number of subclasses, each subclass can obtain its own set of properties and methods by inheritance and transformation, thereby, the parent class shows the commonality and generality, and the subclass shows personality and Features, the abstract level of the parent class is higher than the subclass. Inheriting has the transfer property, the subclass can be derived from the next generation of grandson, relative to Sun class, the subclasses will become their parent class, with a higher level of grandson. This relationship between the inheritance reflects and classes makes the program personnel can define and implement new classes on the basis of existing classes, so it supports the reuse of software components, making it need to add new in the system. The new code required when feature is at least.

4, polymorphism, with a multi-purpose, dynamic set up is closely linked together. The general meaning of polymorphism is that the elements in a certain field can have a variety of explanations. The polymorphism is in the form as a method to pass the parameters transmitted to it, and different methods can be invoked to achieve different operations. Map polymorphisms into the real world, the same thing as the same thing, as the environment can have different expressions and different and other things in communication. Dynamic setup is a facility that connects the method name with the corresponding method, which makes the feature automatically applies to the object. Applying polymorphism concepts to object programming, enhances the simulation of the program to objective world, making object programs with better readability, making it easier to understand. A variety of facilities support polymorphic facilities are available in programming languages, such as a multi-purpose, class genus, and inheritance mechanism is a supported polymorphic facility unique in the object language.

5, dynamically set up, as mentioned above, dynamic set up is the concept associated with the polymorphism, dynamically set the side, and the function is implemented is to call the variable with its value, process call to the corresponding executable code. Determine and connected. For polymorphic variables, the compilation time can only determine the range of its polymorphism (ie dynamic type set). For multi-state operations, the code that implements this operation can only be determined at runtime. Dynamic Ding'an facilities add a conciseness and easy expansion of programming language. The object-based programming is based on the above basic concepts, which has great improvements compared to the traditional programming method. The traditional programming method is based on functionality, the top-down "black box method"; the object-based programming method is based on the object, the above-end, quot; white box law ". Compared with the object design method, tradition The program design method has a significant shortcomings in the following points:

1, "Black Box Law" is based on functionality, functionality is volatile, so the procedure has instability, variability, and difficult to adapt to changes in system evolution, often functional changes means redesign.

2, "Black Box Law" cannot be directly simulated on the objective world, so it is indirectly, and the naturalness of human-computer interaction language is poor, and the difficulty of maintenance procedures for program developers is increased.

3, "Black Box Law" based on function, resulting in poor levels of programs, expandability, portability, software components are difficult to reuse, software development usually cannot borrow existing labor.

Object programming method ------ "White Box? Quot ;, under the following points:

1. Use "class" and "object" concept to simulate the objective world directly, the objective world, the properties of things, the contacts between things, and the relationship between the things can find the corresponding mechanism in the object design language. The object-based programming method is reasonable, which in line with the law of people knowing things, improves the readability of the program, making human machine more close to the natural language, which is a very good compared with traditional programming methods. Big progress.

2, the object-based programming method is based on problem object, the problem object template is the real object in the real world. The object program is designed from internal structures to simulate the objective world, compared with the traditional programming method based on functional simulation. The object is more stable than the function, and the function may be a moment of changing. Maybe a day changed one, maybe one and a half months change, but the problem object is relatively stable, so the simulation problem object is better than the simulation function makes the program have better stability, also Difficult to reduce the difficulty of program staff.

3. A number of additional programs, portability facilities are available in the object program. Such as inheritance facilities, polymorphism, interface facilities. Inheritance facilities and polymorphic facilities have been mentioned before. The interface is a facility for external user calls. External users operate the object by calling an interface of an object to complete the corresponding function, so that the status of the object changes, or operates for other objects to achieve new Object or communication with other objects. The interface of the interface facility has many benefits, and the interface can be seen as an object to keep in touch with the outside world. An object passes the information from the outside through the interface, and the information is passed through the interface, which reflects that an object is generated throughout the process to the entire process, the interface setting embodies the autism and closure of the object. Authority As mentioned above, the object passes a activity cycle (generated, active, dying), and the object and the external message delivery are completed by the interface; the sealing is interacting with the outside world. Message, realize the changes of its own state, the outside world can not be operated directly, and the private attribute inside the object is blossomed to the outside world. In some object-based programming languages, such as Java, interfaces can also implement multiple inheritance functions between classes, and avoid common multiple inheritances also referred to as "diamond inheritance". Unexpected questions. Describe an interface type, with the subclass of the interface type as the parent class, only inherit the parent class, not inherited, and solves the problem of the path uncertainty in the implementation inheritance attribute, and achieves multiple inheritance functions. 4, the relationship between the class and classes in the object program has inheritance relationship, reference relationship, these two relationships simulate the relationship between the objective world between China, "Yes" and "there is". There are two things in the objective world, assuming things A and things B. If there is a relationship between A and B in A, the relationship is used in the A and B, we need to establish a transparent relationship between class A and class B, A is a reference class, B is allowed Use the class, and the variables in A are set to x, and there is a statement like X: b; if there is a "YES" relationship between A and B, such as a special case of B, then an object simulation At the time, class A and class B are inheritance relationships, A is derived, b is the base class, and in the inheritance portion of the class A, there is a statement such as inherit B. The introduction of these two relationships between the class provides a great convenience to the program, and can generate new classes on the basis of the original class, saving time and space.

The following is an example of the object programming used in the project as an example, indicating that I understand the design of the object. Network firewall is a valid tool for maintaining network security. Our firewall products developed in the project consist of package filtration and applying agents at all levels. The package filtration and application agents can effectively realize the security of internal network security, prevent external networks from accessing internal network, but package filtering and application agents How to distinguish what is allowed to access the IP address of the internal network, which is allowed to access the 诓 诓      饩 饩 枰    鍪 鍪 鍪 级 级 级 级 嬖 嬖    鍪 鍪 鍪 鍪 鍪 鍪  鍪  Charm rice 娑 ê ǖ ǖ ǖ ǖ P (range), legal users, legal access time, and specific users can enjoy through specific services through specific IP (range), each rule in the rule set At least the following domains: user name, IP address of the source, the IP address, the user-required service name, the service name of the firewall, the action of the user's access, including acceptance, rejection, authentication, rule work effect Time, including start time and end time, by using rules, constrained the behavior of the package filtration and application agent, generate an effect of rejecting a user access, rejecting access from an IP. The following discussion is how to use the object design method to implement the rule set in the firewall. According to the object development process, the primary work is to identify basic objects in the application field and their interrelationships, and the real object abstraction problem in the objective world, through the analysis of the functions that the firewall should implement and the function modules Analysis of the relationship, we determine that the firewall's rules of the firewall acts to constrain the function of each function module, the rule is existed as a guide module for the package filtering, the application agent module, and each function module should check the rules before the specific function Set, by passing to the rule set related parameters, implementing communication with the rule set module, matches each rule, and obtains the action of the function module to access the specific server from a particular IP to access the internal network at a specific time, It is allowed to access, refuse access, authenticate user identity, or track user access information, through the above analysis, we clarify the rule set we have to achieve is made by several individual rules, through the collection of organizational, each rule is related Domain consists. If the firewall rule set is used as an autonomous, closed object entity, there is also the ability to communicate with other object entities. If the firewall administrator must be able to perform various operations for the rule set, including the added, delete, check, check, If you implement these object-based programming languages, it is manifested as the removal feature of the rule category, and the rule set in the problem object also needs to have a corresponding feature. Because the rule set is composed of rules, each rule has its own independent domain. The matching of rule sets is actually a match for each rule, so each rule needs to match such an external property, the rule set and rule Relationship? Quot; "There is" relationship, put rules abstraction into another problem object, the rule class and rule sets have an enhancement relationship. In this way, we have completed the transformation of the object to the problem object, the next step is to determine the use What kind of computer objects come to simulate problem objects. According to the most conventional representation method, the rule set list is indicated that each element in the list indicates a rule, and the linked list has a header and the tail, and each element in the list is a pointer. It is pointed to the next element, and the chain-based operation is: addRule, indicates adding a rule; removeAll, indicates that all rules are deleted; Checkrule, indicate the check rule set, and return the check results.

Rule uses another class, each attribute in the class corresponds to each domain in the rule: RuleID is a unique sign that each rule is different from each other; UserList, represents the username; DESTBEGIN, DESTEND, indicates the IP range of Subtu, SourceBegin, Sourcend, represents the IP range of the source; DestportBegin, destportend, indicates the port range of the content; Action, indicates the action of the function module that matches the successful function module; beGintime, endtime, indicates the effective start time of the rule; serviceName, represents the service name that is allowed NextItem, pointing to the next rule. The operations on the rules are: checkrule, indicating the matching of the rules, which requires matching the rule username, source IP, the SB, the Subt, the Source, and the valid time, which is the specific implementation of Checkrule in the rule set. This determines the computer object, you can start, the following is an example of our implementation set and rules: (indicated with C code) class crule {private: crule_item * pruleListhead, // Head * pruleListtail; // Public: crule (void); ~ Crule (void); ... void removeall (...); void addrule (...); bool checkrule (...);}; class crule_item {public: int RuleID; // target rule number CUserList UserList; // username unsigned int DestBegin, DestEnd; // All in net orderunsigned int SourceBegin, SourceEnd; WORD DestPortBegin, DestPortEnd; char action; // action SYSTEMTIME BeginTime; // rule effective The start time systemtime endtime; // rule valid end time cstring serviceName; CRULE_ITEM * NextITEM; Private: ... ... BOOL ISSourceValid (...); // Judgment the source IP is effective BOOL ISDestvalid (.. .); // Determine if the contents of the content IP is valid BOOL ISDESTPORTVALID (...); // Determine if the Subbu port is effective BOOL ISTIMEVALID (...); // Judgment whether or not the rule is the effective time BOOL ISUSERVALID (...); // The two iSuserValid functions are the example of function polymorphism BOOL iSUSERVALID (...); //, determine if the user name is effective public: crule_item (void); ~ CRULE_ITEM (Void); Bool Checkrule (...); }; Note: The part expressed in "..." is already implemented in the program, ourselves. In the project implementation, by using the object programming method, we fully feel its convenience, with better readability and reusability through its program, convenient, and convenient Ordinary users.

转载请注明原文地址:https://www.9cbs.com/read-25124.html

New Post(0)