Design class is like design type -- Objective C ++ learning notes

Source: Internet
Author: User
Design class is like design type (treat class design as type design .)

The design class should be designed with the same caution as "when the language designer designed the built-in type of the language.

Class is also a types. Good types have natural syntax, intuitive semantics, and one or more efficient implementations.

ClassDesign Checklist:

1,
New TypeHow should I create and destroy objects?

2,
What is the difference between object initialization and object assignment?This determines the behavior of the class constructor and the assignment operator, and the difference between them. It is important not to confuse initialization and assignment.

3,
New TypeIf the object is passed
By Value
(Passed by value), what does it mean?The copy constructor defines how to implement the pass-by-value of a type.

4,
What is new type??Generally, only some value sets are valid for class member variables. The numeric sets determine the constraints that your class must maintain, and you will feel that your member functions (especially constructors, value assignment operators, and the so-called seter functions) must perform error checks.

5,
Your new typeNeed to work with an inheritance system?If you inherit from some existing classes, you will be constrained by the design of those classes, especially the impact of their functions being virtual or no-virtual. If other classes are allowed to inherit your class, whether the declared function, especially the destructor, is virtual.

6,
Your new typeWhat kind of conversion is required?If you want things of Type T1 to be implicitly converted to things of Type T2, it is necessary to write a non-explicit it-one-argument (which can be called by a single real parameter) constructor T2 in T1 or T2. If you only allow the existence of the explicit constructor, you must write a function specifically responsible for conversion and not be a type conversion operator (type conversion
Conversion operator) or non-explicit-one-argument constructor. Avoid implicit conversion whenever possible.

7,
What kind of operators and functions?Is it reasonable?

8,
What kind of standard functions should be rejected?For example, the constructor may declare the function as private, that is, the new operation is not allowed.

9,
Who should use type??This can determine which members are public, which are protected, and which are private, and which classes and functions are friends.

10,
Declarative New Type?

11,
Your new typeHow General is there?Maybe you don't define a new type, but define an entire types family. If so, you should not define a new class, but define a new class template.

12,
You really need a new type?If you only define a new derived class to add new functions to the existing class, it is better to simply define one or more non-members functions or templates.

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.