Object-oriented Basic concepts
Geogo in Shenzhen (2007-01-13)
Object-oriented (object-oriented; short: OO)
So far there is no unified concept, I define it as: according to people to understand the objective world system thinking mode, the use of object-based (entity) concept to establish a model, simulation of the objective world analysis, design, implementation of the software approach. Through the object-oriented concept, the computer software system can correspond with the real-world system one by one.
The object-oriented approach (Object-oriented method) is a methodology based on the concept of "object", which applies the object-oriented idea to the software development process and directs the development activities of the system method, or the OO (object-oriented) method. An object is a package of data and allowable operations that directly correspond to an objective entity, and an object class defines a set of objects with similar properties. Each inheritance is a way to share the properties and operations of classes that have hierarchical relationships. The so-called object-oriented is based on object concept, Object-centered, class and inheritance as the construction mechanism, to recognize, understand, depict the objective world and design, build the corresponding software system.
As a new and unique method, object-oriented approach is attracting more and more attention and attention in the world, and it is regarded as "a good method to study high technology", which is the focus of the current computer industry. For more than more than 10 years, many experts and scholars have predicted that, as a result of the 70 's structural approach to the application of computer technology, the 90 OO approach will strongly influence, promote and promote a series of high-tech development and multidisciplinary integration.
The origin and development of object-oriented approach
Review history can inspire now to plan for the future.
The Oo method originates from an object-oriented programming language (abbreviated as OOPL). In the late 50, when writing large-scale programs in FORTRAN language, variable names often occurred in different parts of the program. In view of this, Algol language designers in the ALGOL60 adopted the "Begin ... End "is the block of the identity, so that the variable names inside the block are local so that they do not conflict with a variable of the same name outside the block in the program. This is the first attempt to provide encapsulation (protection) in the programming language. Since then the block structure is widely used in high-level languages such as Pascal, Ada, C.
In the late 60, the Simula language was developed on the basis of ALGOL, and it developed a step forward in the concept of ALGOL block structure, put forward the concept of object, and used class and support class inheritance. In the 70 's, Smalltalk language was born, it took Simula's class as the core concept, and many of its contents borrowed from Lisp language. After continuous research and improvement on SMAUTALK72 and 76, Xerox Corporation introduced commercialization in 1980, emphasizing the unity of object concept in system design, introducing concepts and terms such as object, object class, method and example, using dynamic linking and single inheritance mechanism.
Since the 80 's, people have carried out a great deal of theoretical research and practical exploration based on the concepts of information concealment and abstract data types, as well as the foundation laid down by MODULA2, Ada and Smalltalk and other languages, along with the promotion of objective demand. Different types of object-oriented languages (such as: Object-c, Eiffel, C + +, Java, object-pascal, etc.) gradually develop and build up a more complete and springing research and development, the concept of OO method of theoretical system and practical software system.
Object-oriented source for Simula, real oop is laid down by Smalltalk. Smalltalk is now considered to be the purest oopl.
It is through the development and application of Smalltalk80 that people notice the unique features of the Oo method, such as modularization, information encapsulation and concealment, abstraction, inheritance, diversity and so on, these excellent characteristics are the development of large-scale software, improving software reliability, reusability, Extensibility and maintainability provide an effective means and approach.
Since the 80 's, people have applied the basic concept and operation mechanism of object-oriented to other fields, and obtained a series of object-oriented techniques in corresponding fields. Object-oriented approach has been widely used in programming language, formal definition, design methodology, operating system, distributed system, artificial intelligence, real-time system, database, human-computer interface, computer architecture and concurrent engineering, integrated engineering, etc., in many areas of application has been a great development. The first international conference, "object-oriented programming, systems, languages and applications (OOPSLA ' 86)", was held in the United States in 1986, bringing the world's attention to object-oriented, followed annually, which further marked the spread of research into the OO approach worldwide.
The object-oriented method has been greatly developed in the 80 's, and has been applied effectively in computer science, information science, System science and industry, showing its strong vitality. Can be expected in the 90 's, the object-oriented approach will be much deeper, more officials and higher direction to make progress: (1) Deeper direction: such as the theoretical basis and formal description of the Oo method, using OO technology to design a new generation of OS and so on. (2) Broader direction: object-oriented knowledge representation, object-oriented simulation system, object-oriented multimedia system, object-oriented virtual reality system, etc. (3) Higher direction: Enrich the essential attribute of OO methodology from the height of thinking science, break through some limitations of the existing object-oriented technology, and study the unified object-oriented paradigm.
Objects (object)
Refers to a variety of entities in the real world. It can refer to a specific thing or an abstract thing. such as: integers 1, 2, 3, Rogue Chen Shui-bian, Apple, aircraft, rules, laws, regulations, forms and so on. Each object has its own internal state and laws of motion, such as the name of the rogue Chen Shui-bian, height, weight and other internal conditions, with eating, sleeping, hitting, tax evasion, such as law of evasion. In object-oriented concepts, we refer to the internal state of an object as a property, a law of motion as a method or an event.
The object is anything to be studied. From a book to a library, a single integer-to-integer database, an extremely complex automation plant, and a space shuttle can all be seen as objects, not only to represent tangible entities, but also to represent intangible (abstract) rules, plans, or events. An object consists of the data (the attributes that describe things) and the actions that are used for the data (the behavior that manifests things) as an independent whole. From the programmer's point of view, the object is a program module, which, from the user's perspective, provides them with the desired behavior. Internal operations are often referred to as methods.
An object can be either an object of a specific physical entity, an artificial concept, or anything that has a definite boundary and meaning. For example: An employee, a company, loans and borrowings, etc., can be used as an object
Classes (Class):
A class is a collection of entities (or collectively, abstractions) that have similar internal and motion laws. The concept of class comes from the process of people's understanding of nature and society. In this process, people mainly use two methods: from the special to the general induction and from the general to the special deduction. In the process of induction, we draw together the common features from one specific thing to form a general concept, that is, "classification", such as: insects, lions, reptiles, because they are active so classified as animals. In the process of deduction, we also put the same kind of things, according to different characteristics into different small categories, which is "classification", such as animals, cat, cat, and so on. For a specific class, it has many specific individuals, and we call these individuals "objects". The internal state of a class refers to the common state of objects in a class set, and the movement law of a class refers to the common motion of objects in a class set. such as: Plato the following definition of man: Man is no hair can walk upright animals. In the definition of Plato "Man" is a class, with "No hair, upright walk" and other things different from other common characteristics, while Zhang San, John Doe, Harry, Rogue Chen Shui-bian, such as a specific person, is "person" this category of "object".
A class is a template for an object. A class is a definition of a group of objects that have the same data and operations, and a class contains methods and data that describe the common properties and behavior of a set of objects. A class is an abstraction on top of an object, which is the materialization of a class and an instance of a class. A class can have its subclasses, or it can have other classes that form a class hierarchy.
In object-oriented software technology, "class" is the definition of a similar set of objects with the same data and operations. That is, a class is a description of one or more objects that have the same properties and behavior, and often in this description includes a description of how to create a new object for that class. In layman's words: A class is an abstraction of a set of similar objects that have the same properties and behavior.
Method:
A method is an action that an object can perform, that is, a service defined in a class. The method describes the algorithm that the object performs the operation on, and the method that responds to the message.
Property:
A property is a data defined in a class, which is an abstraction of the nature of an objective world's reality. Each instance of a class has its own unique property value. For example, name and gender can be used as attributes of employees.
Abstract Class:
Abstract class, which cannot be used to create an object instance, but exists only as a template for creating its child classes. For example, "line" is an abstract class of "straight line" and "curve".
The relationship between classes and classes:
Dependency (Dependency):
The semantic relationship between two things, in which one thing has changed affects another.
Association (Association):
is a structural relationship that describes a set of chains, which are links between objects. For example, a person working for a company (worksfor), here worksfor is an association.
Link:
is a physical or conceptual connection between objects. For example: Zhang San is working for Microsoft (worksfor), where WorksFor is a link.
Aggregation (Aggregation):
It is a special form of association. Represents the relationship between the whole and the part. For example, the relationship between a project group and its members is an aggregation relationship.
Composition relationship (composition):
It is also a special form of association. means that the whole has parts and parts that coexist with the whole. For example, a window is made up of text boxes, list boxes, menus, and so on. Close the window, each component also disappears, the relationship between the window and its components is a combination of relationships. Between Featureclass and feature in AO objects is a kind of combinatorial relationship.
Generalization (generalization):
It is a special/general relationship in which the object of the special element (child element)/is substituted for the general element (parent element) of the object. Also known as "is a relationship".
Implementation (Realization):
is a semantic relationship between the classes, where one class element specifies a contract that is guaranteed to be executed by another class element.
Instance:
An instance is a specific object that is described by a particular class. For example, a car is an example of a vehicle. In fact, the class is the "template" used to build the object, according to the template created by a specific object, is the real example of the class, for short instance.
Note: When using the term "object", you can refer to a specific object or generic object, but when using the term "instance", it must refer to a specific object.
Messages (message):
Messages are the ways in which objects are interconnected and interacting. A message consists of 5 parts: the object that sends the message, the object that receives the message, the message delivery method, the message content (parameters), and the feedback.
A message is a specification of the communication between objects. Typically it consists of three parts: the object that receives the message, the name of the message, and the actual variable.
Properties of the class:
The definition of a class determines that the class has the following 5 attributes: Abstract, inheritance, encapsulation, overloading, polymorphism.
Abstract:
The definition of a class explicitly states that a class is an abstraction of an object with internal state and motion laws, an abstraction is a way of looking at things from a general point of view, which requires that we focus on the essential characteristics of things (internal and motion), not specific details or implementations. Object-oriented encourages us to look at the real world in an abstract way, that is to say, the real world is a set of abstract objects-the class composition.
Inherited:
Inheritance is the relationship between classes at different levels of abstraction. The definition of the class is mainly 2 ways of induction and deduction; The general class that is summed up by some special classes is called the parent class of these special classes, the special class is called the subclass of the General class, the same parent class can deduce the subclass, and the parent class is a higher level abstraction of the subclass. Subclasses can inherit all the internal state and motion laws of the parent class. In the development of computer software, the inheritance is provided, the hierarchical structure of the class is given, and the common characteristics can be shared by the class inheritance, which improves the reusability of the software.
Inheritance is the mechanism by which subclasses automatically share data and methods between parent classes. It is represented by the derivation function of the class. The entire description of a class directly following the other classes can be modified and expanded. The secondary post has the reception of the front. The secondary is divided into single inheritance (a subclass has only one parent) and multiple inheritance (a class has more than one parent class). The objects of the class are closed, and if there is no inheritance mechanism, the data and methods in the class object will be duplicated a lot. Inheritance not only supports the reusability of systems, but also facilitates the extensibility of the system.
Broadly speaking, inheritance refers to the ability to directly acquire existing properties and features without having to define them repeatedly. In OO software technology, inheritance is the mechanism by which subclasses automatically share data and methods defined in a base class. Inheritance makes it possible for similar objects to share program code and data structures, which greatly reduces the redundancy information in the program. When a class is allowed to inherit only one class, the inheritance of the class is single-inheritance, such as in the C # language, where one class inherits from the other, only single inheritance, and the C + + language allows a class to inherit multiple classes.
Packaging:
The interaction and interaction between objects is mainly realized through the message mechanism. There is no need to get too much information about the specific state or motion patterns of the other person. An object-oriented class is a well-encapsulated module in which the class definition explicitly separates its description (the user-visible external interface) from the implementation (an internal implementation that is not visible to the user), and its internal implementation provides protection according to the scope it specifically defines. Class is the most basic unit of encapsulation. Encapsulation prevents the change effect of program interdependencies. The method that is defined in the class to receive the other message is called the interface of the class.
Encapsulation is an information concealment technique, which is embodied in the description of the class and is an important feature of the object. Encapsulation makes the data and the method (function) of processing the data encapsulated as a whole, in order to achieve a very independent module, so that the user can only see the external characteristics of the object (the object can accept which messages, with those processing power), and the object's internal characteristics (the preservation of the internal state of private data and the implementation of processing capacity algorithm) is The purpose of encapsulation is to separate the use of the object's designer from the object, and the user does not have to know the details of the implementation of the behavior, but only accesses the object with the information provided by the designer.
The so-called encapsulation is to wrap something up, so that the outside world does not know the specific content of the thing. It exists through the form of an interface to the outside world. For example, turn on the TV, it provides an open/Close button, its actual content, how to let the TV play we do not know. We don't have to worry about that much, we just need to know that we can do what we want with this action. Through encapsulation, we implement the details of the outside of the hidden, so as to achieve the data description and operation to achieve the purpose of separation, the user only need to know its description can use it.
Polymorphic (overlay):
Polymorphism means that methods of the same name can have different motion laws in different classes. When the parent class is interpreted as a subclass, the law of motion of the class can also be deduced, and the deduction makes the law of motion or motion of the same name of the sub-class more specific, even the subclass can have a different motion or motion form than the parent class. Different subclasses can deduce different laws of motion.
The object is acting according to the received message. When the same message is accepted for different objects, it can produce completely different actions, known as polymorphism. The use of polymorphic users can send a common message, and all implementation details are left to the object receiving the message, so the same message can invoke different methods. For example, the printing method that is called when the print message is sent to a graph or table is completely different from the printing method that is called when the same print message is sent to a body file. The implementation of polymorphism is supported by inheritance, with the hierarchical relationship of class inheritance, the protocol with common function is stored at the highest level of class, and the different methods of implementing this function are placed at a lower level, so that the objects generated at these low levels can respond differently to generic messages. Polymorphism can be achieved in OOPL by redefining a base class function (defined as an overloaded function or virtual function) in a derived class.
A subclass object can be used as a parent object, and the same message can be sent to the parent class object or to a subclass object. That is, the name of a behavior is shared between the parent class and its subclasses, but can be implemented according to their actual needs. The polymorphism mechanism not only increases the flexibility of the object-oriented software system, but also reduces the redundancy of the information.
Overload:
Overloading refers to the method of the same name in the class to pass different parameters to it can have different motion laws. When interacting with objects, even if the receiving Message object takes the same receive method, but the content of the message is different in detail, the motion rule inside the receiving message object may be different. 4, the boss assigned a buyer to buy things, when the boss did not specify what to buy, the buyer may default to buy sweet potatoes, if the boss indicates to buy a buyer of rice, the buyer may go to the nearest supermarket to buy 10 pounds of rice; If the boss indicates that the buyer to the east corner of Fuzhou to buy 5 Jin Rice, the buyer will have to Place to buy 5 pounds of rice.
function overloading refers to the function names that can be used by functions with different parameters in the same scope. Operator overloading means that the same operator can be applied to different types of operands. Overloading plays a good role in improving the flexibility and readability of the system.
Package:
Philosophy holds that the interaction and interaction between different objects in the real world constitute a variety of systems, and the interaction and interaction between different systems constitute a larger system, which in turn constitutes the whole world. These systems are referred to as packages in object-oriented concepts.
The interface class for the package:
In order to contain the concrete implementation of the system, the system interacts with other systems by setting up interface classes or objects, so that other systems can only see this interface class or object, which is called an interface class in object-oriented.
In this paper, it is shown that in OO methods, objects and transitive messages represent the concept of the relation between things and things respectively. Classes and inheritance are descriptive paradigms that are adapted to the way people think in general. The method is to allow various actions on the class object. The basic point of this programming paradigm for objects, classes, messages, and methods lies in the encapsulation of objects and the inheritance of classes. By encapsulating the object's definition and the realization of the object, the inheritance can embody the relationship between class and class, and the dynamic link and entity polymorphism, thus constituting the basic characteristic of object-oriented.
Object-oriented new methodology, new paradigm and new technology
The function and significance of OO method is not confined to programming technology, it is a new type of programming paradigm-object-oriented programming paradigm, it is a new methodology of information system development-object-oriented methodology, is the emerging new technology-object-oriented technology.
Object-Oriented Programming paradigm: Programming paradigm (hereinafter referred to as the model) specifically refers to the design of the genre, just as the literature has novels, poetry, prose and other genres, programming style is to use programming language to express various concepts and various structures of a set of facilities.
At present, the scope of the model is divided into: the process of setting the model, the function of the set model, in addition to the process of setting the model, event set model and type system mode. Each model has a variety of programming language support (such as: FORTRAN, PASCAL, C are embodied in the process of the model, for process-oriented programming), and some languages have a variety of paradigms (such as: Lisp process and function mixed model, C + + is the language of the process and object-oriented hybrid paradigm).
Over-the-top programming paradigm is the most popular program design paradigm (most of the programming languages that people use usually belong to this type written off they are process-oriented languages), which is the design process, so the first thing to decide is the process of solving the problem, and then the algorithm of the design process. This type of language must provide facilities for the process (function) to transmit the value of the variable and return, how to distinguish between different kinds of processes (functions), how to transfer the variable is a major concern in such programming.
The object-oriented programming model is developed on the above paradigm, its key is to add class and its inheritance, to use the class to represent the common attribute, subclass inherits the attribute of the parent class, and can add new features. The object is created as a template for the class. Therefore, in object-oriented programming, the first task is to determine the required classes, each class should set sufficient operations, and use the inheritance mechanism to share the common characteristics of two. In short, the object-oriented programming model has the characteristics which other paradigms lack or does not have, extremely rich vitality, can adapt to the complex large-scale software development. To be sure, this new type of model will definitely push forward the new development of software. Confined to space, the other set of the model is not described here.
Object-oriented methodology: The OO approach follows the general concept of cognitive methodology (i.e., from general to special and inductive-from special to general, complete theory and method System) and establishes the object-oriented method. One of the main points of object-oriented methodology: to think that the objective world is composed of various "objects", everything is an object, each object has its own motion and internal state, each object belongs to an object "class", is an element of the object class. Complex objects can be made up of a relatively simple variety of objects in some way. The combination and interaction of different objects constitute an objective system to be researched, analyzed and constructed. The main points of object-oriented methodology are: By analogy, we find the similarity between objects, that is, the common attribute among objects, which is the basis of the object class. When the concept of the quot; class, parent, subclass, or sub-class forms the hierarchical relationship of an object class, an object at the next level can naturally inherit the properties of the object at the previous level without special instructions. Object-oriented approach the first point of preschool: think of the various objects that have been divided into classes, you can define a set of "methods" to describe the function of the object, that is, allow the action on the object on the various operations. The interaction between objects is accomplished by passing a message that informs the object to complete an operation that allows the object to be manipulated, and the details of how the object will complete the operation are encapsulated in the definition of the corresponding object class, and the details are hidden from the outside world.
It can be seen that the Oo method has a strong concept of class, so it will be able to intuitively simulate the way of human understanding of the objective world, that is to imitate the human in the cognitive process from the general to the special deductive function or from the special to the general induction function, the concept of the class reflects the object object's essential properties, It also provides a theoretical basis for implementing the mechanism of object sharing.
When we develop the software system according to the idea of object-oriented methodology, we first want to do the object-oriented analysis (Ooa――object oriented), whose task is to understand the objects involved in the problem domain, the relationship between the objects and the action (that is, the operation), and then construct the object model of the problem. The model can realistically reflect the "real problem" to be solved. In this process, abstraction is the most essential and important method. In order to choose different levels of abstraction for different nature of the problem, it will affect the understanding and solution of the essential attribute of the problem.
The second is the object-oriented design (Ood――object oriented analysis), which is the object model of the design software. According to the function of the object-oriented software development environment, it may be reformed on the basis of the analysis of the object model of the problem, but it should be based on the principle that the object model of the original problem domain should be changed at least. Then in the software system to design each object, the relationship between objects (such as hierarchical relationships, inheritance relationships, etc.), communication between objects (such as message patterns), in short, the design of each pair of quot;
The final stage is the object-oriented implementation (ooi--object oriented zmplementation), which refers to the implementation of the SOFTWARE function, which includes: the implementation of the internal functions of each object, the establishment of the object which some of the processing capacity should be described in which classes, determine and implement the system interface, The form of output and other control mechanisms, in short, is to achieve the ood phase of the various objects required to complete the task.
Object-oriented programming with OO method, the basic steps are as follows: (1) The analysis determines all the objects and their attributes appearing in the problem space and reconciliation space, and (2) determines the operation that should be applied to each object, that is, the inherent processing ability of the object, and (3) analyzes the relations between the objects, and determines the messages that the objects The design object's message pattern, the message pattern and the processing ability together constitute the object's external characteristic, (5) analyzes each object's external characteristic, the object having the same external characteristic is classified as a class, thus determines the required class, (6) determines the inheritance relation between the classes, the public nature of each object is placed in the higher class to describe, To share the description of the public nature through inheritance, (7) to design a description of each class about the external characteristics of the object, (8) to design the internal implementation of each class (data structure and methods), (9) to create the desired object (an instance of the class), and to implement the appropriate connection (message) between objects.
Object-oriented technology: Technology "refers to the production of practical experience and the principle of natural science
And the development of a variety of process operation methods and skills ";" Broadly speaking, it also includes the corresponding production tools and other material equipment, as well as the manufacturing process or operating procedures, methods. Oo method is not only a new paradigm of program design, system development of new methodology, as a new technology it has a basic basis, in fact, the OO method can support a variety of system development, has been or is being applied in many ways, so it can be said that the Oo method is a new technology-object-oriented technology.
In the last more than 10 years, in addition to object-oriented programming, OO method has been applied to the whole information system field and some new industries, including: User interface (especially GUI ――gui), application integration platform, object-oriented database (OODB), distributed system, network management structure, The field of artificial intelligence and concurrent engineering, integrated engineering and so on. Artificial intelligence is a new field closely related to computer, and in many aspects, it has adopted object-oriented technology, such as knowledge representation, expert system construction and user interface. Ai software is often large, and it is possible to better design and maintain such programs with object-oriented technology.
The development of concurrent projects in the late 80, the concept of the main point is that in the early stage of product design (i.e., the plan phase), the structure, process, processing, assembly, testing, use, market and other issues in parallel to start the operation, its implementation must have two basic conditions: one is the Expert group, and the second is to share and manage CAE, cin tightly combined). Obviously, this requires support for object-oriented technology. At present, some companies have been using concurrent engineering product development, has achieved significant benefits: Boeing to develop a giant 777 transport aircraft, than the development of 767 to save 1.5 time; Japan used concurrent engineering for new models of car production, compared with the United States in half the time. Industry believes that their survival depends on concurrent engineering, and object-oriented technology is an important support for the development of concurrent engineering.
Integrated engineering is a new engineering concept to develop large open complex systems, similar to concurrent engineering, the organization of expert groups and sharing of information is the two pillars of support for the concept. Because the open large-scale system contains people's intelligent activities, it is very difficult to establish mathematical model, and OO method can be more natural to the real world, easy to achieve the consistency of problem space and program space, can support the establishment of complex system hierarchy model at various levels, and is an important tool to study integrated engineering.
The role of object-oriented technology in concurrent engineering and integrated engineering, on the one hand, illustrates the wide application scope of this new technology, but also shows its important influence, and proves that object-oriented technology is a new technology that deserves wide attention.
In summary, it can be concluded that the OO method for system development has the following advantages: (1) Emphasis on the real world from the objective things (objects) to understand the problem domain and construction system, which makes the system developers greatly reduce the difficulty of understanding the problem domain, so that the system can more accurately reflect the problem domain. (2) The use of human daily thinking methods and principles (embodied in the Oo method of abstraction, classification, inheritance, encapsulation, message communication and other basic principles) for system development, beneficial to play the human thinking ability, and effectively control the system complexity. (3) The concept of the object runs through the end of the development process, so that the system components in each development phase are well aligned, thus significantly improving the system's development efficiency and quality, and greatly reducing the difficulty of system maintenance. (4) The consistency of the object concept, so that all kinds of people participating in the system development have a common language in the development of each section, effectively improve the communication and collaboration between people. (5) The relative stability of the object and the isolation of the variable factors enhance the strain capacity of the system. (6) The inheritance relationship between object classes and the relative independence of objects provides strong support for software reuse.
Ooa method
The object-oriented analysis method (OOA) is to analyze the problem according to the object-oriented thinking after the systematic business investigation in the process of developing a system. There is a big difference between OOA and structural analysis. OOA emphasizes the analysis and collation of the material for the OO method based on the systematic investigation data, rather than the analysis of the management business status and methods.
Object-oriented Basic concepts