Boundary division of abstract classes

Source: Internet
Author: User

 Recently, we have completed the design and compilation of a framework.

I think about the interface division of the internal base class:

Question: In the most fundamental basic class, define all the sub-class interfaces ??? Is it possible?

1: A system class should have a public root class, And all classes are derived from this root class. This root class can define runtime variables to record the types of each class.

Cause: It is good to abstract the interface of the entire system.

For example, all class references of the system can be replaced by the application of the root class object, which provides convenience for future interface overloading.

2: The base class only contains the member variables that must be included in its subclass. Base ClassLessDefine member variables.

For member variables that are not included in all subclasses, do not write them in the base class. You can add a derived level to include the corresponding member variables.

Cause: Avoid subclass containing unnecessary member variables, so that the subclass object of the class occupies unnecessary memory.

3: According to 2, the base class should also be divided into different levels. In principle, you can add an abstract base class to a group of classes that have something in common.

4: Similarly, the basic class interface is only responsible for the public operations of its corresponding subclass group. (The reason is that it is impossible to write all the operation functions of the Child classes of the derived hierarchy in advance .)

5: the most important thing is to define the logical organization rules that all child classes should comply.

E. g:

Class

{...

LIST/<A/> itmes;

}

Class B: public

{

}

...

Then, subclass B of A is self-contained.

 

5: The relationships between classes (especially the combination and aggregation relationships) reflected in the class diagram should be reflected in the superclass, but the object member variables whose combination/aggregation can not be written out in the superclass, however, you must write an operation interface for the combined/aggregated variables.

E. g:

Class A // Objective C

{....

Interface for operating aggregate variable B

...

Interface for aggregating variable C

...

However, a does not contain members of the B and C types.

}

A little smile.

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.