Object-oriented and Windows Programming

Source: Internet
Author: User

Object-oriented technology is a popular system design and development technology. It includes Object-Oriented Analysis and object-oriented programming. The proposed object-oriented programming technology mainly aims to solve the code reuse problem which cannot be solved by the traditional programming method-structured programming design.

Structured Program Design starts with the functions of the system. According to Engineering Standards and strict specifications, the system is divided into several functional modules. The system is a set of functions and processes that implement the functions of the module. Due to the constant development and changes of user needs and software and hardware technologies, the system modules designed according to functions must be changeable and unstable. In this way, the developed modules are not highly reusable.

Object-Oriented Programming starts with the processed data and describes the system with the data as the center rather than the Service (function) as the center. It regards programming as a data set, and the data is more stable than the function.

The biggest difference between object-oriented programming and structured programming is that the former is concerned with the data to be processed, while the latter is concerned with functions first.

Object-Oriented programming is a program design method that organizes models around the concept of the real world. It uses objects to describe the entities of the problematic space. There is no uniform definition of object. Generally, an object is an abstract entity that contains the characteristics of an object in the real world. It reflects the ability of the system to store information and/or interact with it. It is an encapsulation body of some attributes and services. In the field of programming, it can be expressed by the formula "Object = Data + actions on these data.

A class is a collection of objects with the same operation functions and the same data format (attribute. Class can be seen as the specific implementation of abstract data types. Abstract data types are abstract representations of data types. A data type is a set of exponential data and a set of operations acting on it. abstract data types do not care about the operation implementation details. From the external perspective, the type of behavior can be specified by the newly defined operation. Class is the abstraction of the object set, which specifies the public attributes and methods of these objects; the object is an instance of the class. Apple is a class, while the apple on the table is an object. The relationship between objects and classes is equivalent to the relationship between variables and variable types in general programming languages.

A message is an expression that requests services from an object. There are methods and data in the object. external users or objects send service requests to the object, which can be called sending messages to the object. Cooperation refers to the shared responsibility and division of labor between two objects.

Object-Oriented programming methods have four basic features:

1. Abstraction:
Abstraction is to ignore those aspects irrelevant to the current target in a topic, so that you can pay more attention to the aspects related to the current target. Abstraction is not intended to understand all the problems, but to select a part of the problem. For example, we want to design a student achievement management system. When we look at the student, we only care about his class, student ID, and score, instead of caring about his height and weight. Abstract: Process abstraction and data abstraction. Process abstraction means that any operation with clearly defined functions can be viewed by users as a single entity, although this operation may actually be completed by a series of lower-level operations. Data abstraction defines the data type and operations applied to this type of object, and limits the object values to be modified and observed only by using these operations.

2. Inheritance:
Inheritance is a hierarchical model that connects classes and allows reuse of encouraging classes. It provides a way to clearly express commonalities. A new class of an object can be derived from an existing class. This process is called class inheritance. The new class inherits the features of the original class. The new class is called the derived class (subclass) of the original class, and the original class is called the base class (parent class) of the new class ). A derived class can inherit methods and instance variables from its base class, and the class can modify or add new methods to make it more suitable for special needs. This also reflects the general and special relationship between nature. Inheritance solves the reusability of software. For example, all Windows applications have a window, which can be viewed as derived from a window class. However, some applications are used for text processing, and some applications are used for drawing. This is because different subclasses are derived and different features are added to each subclass.

3. encapsulation:
Encapsulation is one of the characteristics of object-oriented, and is the main feature of object and class concepts. Encapsulation is to enclose the process and data. Data access can only be performed through the defined interface. Object-oriented computing begins with the basic concept that the real world can be depicted as a series of completely autonomous and encapsulated objects that access other objects through a protected interface. Once an object's features are defined, it is necessary to determine the visibility of these features, that is, which features are visible to the external world and which features are used to represent the internal state. Define the interface of the object at this stage. In general, direct access to the actual representation of an object should be prohibited, but the object should be accessed through the operation interface, which is called Information Hiding. In fact, Information Hiding is a user's understanding of encapsulation, and encapsulation provides support for information hiding. Encapsulation ensures that the module has good independence, making program maintenance and modification easier. Modifications to an application are limited to the internal class, so that the impact of application modifications can be minimized.

4. Polymorphism:
Polymorphism allows different types of objects to respond to the same message. For example, in the same addition, adding two times together and adding two integers together must be completely different. For example, the editing and pasting operations have different effects in the word processing program and drawing program. Polymorphism includes parameterized polymorphism and inclusion polymorphism. The polymorphism language has the advantages of flexibility, abstraction, behavior sharing, and code sharing, which effectively solves the same name problem of application functions.

Object-Oriented Programming has many advantages:

  • Short development time, high efficiency, high reliability, and stronger development programs. Due to the reusability of object-oriented programming, a large number of mature class libraries can be used in applications, thus shortening the development time.

  • Applications are easier to maintain, update, and upgrade. Inheritance and encapsulation make the impact of application modifications more localized.

The initial development of windows was in the early 1980s s, before the emergence of C ++, but at that time, it was proposed the object-oriented programming idea. Windows developers are aware of the benefits of seeing different items on the interface as objects, but they are still forced to use the traditional C language to process these objects. In the Windows interface design and software development environment, it can be said that the idea of object-oriented is everywhere.

In Windows, the basic unit of a program is not a process or function, but a window. A window is a collection of data and the methods and window functions used to process the data. From the object-oriented perspective, the window itself is an object. The execution process of Windows programs is the process of creating, processing, and killing windows and other objects. Message sending in windows can be understood as a service process in which a window object requests an object from another window object. Therefore, it is extremely convenient and natural to design and develop Windows programs using object-oriented methods.

Using an object-oriented method for Windows programming also simplifies resource management. When we map resources into a C ++ object, the use of resources can be translated into the following C ++ sequence:

1. Create an object. For example, define a paint brush object.

2. Using objects: drawing with a paint brush

3. Undo this object

An object is a process of defining an object. The object constructor can process the resource request process. When an Object exits from the activity range, its revocation can be automatically managed by the compiler. Various resources and Windows structures can be processed in this way, such as device context, paint brush, Font, and paint brush.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.