Introduction to C + + programming thought object

Source: Internet
Author: User

  1. The process of abstraction
    1. All things are objects.
    2. A program is a group of objects that are notified to each other by sending messages.
    3. Each object has its own storage area that is made up of other objects.
    4. Each object has a type.
      • The most important salient feature of the class is "what message can be sent to it"
    5. All objects of a particular type can receive the same message.
      • The transformation of an object enables it to receive the same message as the parent class. Represents the ability to replace OOP ideas.
  2. object has an interface
    • Creating an abstract data type is the basic idea of object-oriented programming. The
    • operates on these variables, known as sending messages or requests, and the object infers what needs to be done based on the message received
    • Class describes a set of objects that have the same attributes (data elements) and the same behavior (functions), so the class is actually the data type.
      • This class I call it a high class. The superclass should have a certain relationship with the design pattern.
    • The request that can be made to an object is defined by its interface (interface), and the interface is determined by the type. interface + Hidden data = implementation (Implementation)
  3. Implementation of the Hidden
    • It is necessary to separate the creator of the class from the client programmer.
    • Packaging, the user should not be exposed to the inside of the machine. You just have to touch the interface of the control machine.
    • Using Access control, you can implement this wrapper on class design.
      1. Reason 1: Prevent client programmers from interfering with the parts they should not touch, so that users know what is important to him, and those he can ignore.
      2. Reason 2: Allow the library designer to change the internal working style of this class without worrying about affecting the client programmer.
    • Public,private,protected.
    • Protected is basically similar to private: inherited classes can access protected, but not private.
  4. Reuse of implementations
    • Include another class as a member of his class in the class. called a combination.
    • When creating a new class, you should consider the composition first, because it is simpler and more flexible.
  5. Inheritance: Reusing interfaces
    • Contains all members and interfaces of the parent class after inheritance.
    • Subclasses are the same type as the parent class.
    • Add a new function to make the subclass different from the parent class.
    • overriding, change the existing base class function so that the subclass is different from the parent class
  6. An interchangeable object with polymorphism
    • Early binding, the compiler generates a call to a particular function name, and the linker resolves the call to the absolute address of the code that is actually being executed.
    • Late binding, when a message is sent to an object, the code that is called is determined when the program is run.
      • The C + + compiler inserts a special piece of binary code where it is actually called. By using the information stored in the object itself, this code computes the address of the called function body at run time.
    • Use virtual to declare a function that wishes to have the flexibility of late binding.
  7. Creating and destroying objects
    • Stack memory
      • To maximize speed, the object is stored in the stack or in a static store, and the storage and lifetime can be determined when the program is written.
      • A stack is an area in memory that can be stored directly by the microprocessor during program execution.
      • Variables in the stack can be called automatic variables, or local variables.
      • The stack is a static storage area, which is a fixed block in memory that is allocated before the program executes.
      • Can be quickly allocated and freed, but at the expense of flexibility, when writing a program, you must know the exact number, life cycle, and type of the object.
      • Creating storage on the stack is often just a microprocessor instruction that moves the stack pointer down, and the other is the move back instruction.
    • Heap Memory
      • You can dynamically determine the type and number of objects to be created at run time.
      • A new object is needed to make it live on the heap using the new keyword directly.
      • When the use is finished, release with the keyword delete.
      • dynamic management at runtime, all time consuming than stack memory usage.
      • In memory on the heap, the programmer must decide when to destroy the object.
  8. Exception handling: Coping with errors
    • Check for errors, and enter the code to handle the error if there is an error.
    • Unlike the traditional C-check error, it is necessary to handle the error condition and cannot be ignored.

Introduction to C + + programming thought object

Related Article

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.