C ++ primer, third edition and design pattern Reading Notes

Source: Internet
Author: User

<C ++ primer> the third edition and <Design Model> are both classic books. Although I have read these two books several times, they are very profound IN THE FIELD OF C ++, there is no unified and complete specification and the changing design model. We can only extract the essence of the master's work for reference at work.

 

The following is an excerpt from the note, which may not follow the contents of this book. The design mode may be added in the middle. Readers may not be able to read this document. Thank you for your understanding.

 

(1) <C ++ primer> third edition:

1. By default, C ++ inherits by value. Each class has all non-static members and methods of the class and the inherited class.

2. virtual inheritance provides a mechanism for inheriting by reference. It supports only one shared base class to be inherited, this prevents duplicate resources in multiple inheritance and instance conflicts (for example, the differences between the inherited base class and the instance base class initialization ).

3. Generally, use as few virtual methods and virtual derivation as possible to save memory space. The principle of use is based on needs.

4. Multiple inherited base classes also include struct.

Example:

// Assume s_base is a struct.

(1) class derived: public base {}; // ordinary single inheritance

(2) class derived: public base <int >{}; // template class instance single inheritance

(3) template <class T> class derived: public virtual base <t >{}; // template class ticket inheritance

(4) class derived: Public s_base {}; // structure ticket inheritance

5. namespace is mainly used for class library development.

6. Construction and copying of prohibited classes

You can set a (const A &); and a operator = (const A &); to a private method.

7. Exception Handling methods include try... catch and exception class construction.

8. The reloads of common operators include ++, --,->, and.

9. The template is divided into function templates and class templates and supports Special and partial special features. The class template also supports youyuan.

10. If you declare a friend function or class in a class, you are granted the right to access non-public members of the class.

11. The construction of abstract classes is implemented through pure virtual functions. In pattern design, abstractfactory and bridge all depend on this.

12. classes can be nested, associated, and struct.

13. struct refers to struct with bit fields and struct without bit fields.

14. For public, protected, and private inheritance, the public members of the base class are derived from the corresponding public, protected, and private members.

15. The advantages of function pointers (including callbacks and combinations in struct ).

16. The template class supports type redefinition to simplify programming. Template Class export.

17. Supported rtti: dynmic_cast, typeid, and typeinfo.

(2) <design mode>

1. flyweight mode: shares a large number of fine-grained objects.

2. Adapter mode: Convert the class interface to another interface you want.

3. Bridge Mode: separates class abstraction and implementation to make them change independently.

4. Facade mode: provides a consistent interface for a group of interfaces.

5. Proxy mode: Provides proxy control for other objects to access specific objects.

6. decorator mode: dynamically add additional responsibilities to objects.

7. iterator mode: provides a method to sequentially access each element of an aggregate object without exposing the internal representation of the object.

8. Strategy Mode: encapsulate a series of algorithms and make them replace each other.

9. Singleton mode: Single Instance

10. Abstract Factory mode: provides an interface for creating a series of related or mutually dependent objects without specifying their specific classes.

Other models are not listed.

Design patterns:

// Access can be divided into inheritance, inclusion, and reference.

(1). the flyweight mode only caches an array or list and provides it to external access.

(2) The iterator mode is similar to the architecture above the flyweight mode, but the random access is changed to sequential (or sequential traversal) access.

(3). the adapter mode is to include the original class (including by creating and external reference) and construct the interface that the user expects. The internal implementation is still implemented through the original class.

(4) The Bridge Mode is similar to the reference adapter mode.

(5) facade is like a vending machine of Coca-Cola.

(6). The proxy mode is a simplified version of the internal creation type of the adapter.

(7). The Strategy Mode is an extension of the concept of polymorphism.

(8). The decorator mode is an extension of the external reference adapter mode.

(9) The Abstract Factory mode constructs factories, workshops, and parts in an abstract way, so that external access is carried out through the abstract factory, and most of the design patterns can be included.

(10). design patterns are not isolated, combinations, variants, and are primarily based on design needs.

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.