[7.1] What is Class?
It is a basic constituent module for object-oriented software.
A class defines a data type, just like the role of Struct in C. In a computer scientific perspective, a type is combined by a series of status and a series of changes in these states. In this case, int can be said to be a type because it has a series of states and it has some operations for these states, such as J J or I , etc. Similarly, a class provides a series of such (usually all PUBLIC type) operations, and a series of data bits indicating the abstract value of this type (usually not public).
You can put intimate as a class with a member function " ", etc. (int is actually not a real, this is to explain the following as a metaphor: a class is a type, it is a type with INT is a type same.)
Note: C programmers can use classes to be a default member is a private C's-type C's Structure. But if it is a reason you think about all things, you may need to do some instances to add some object-oriented experience.
[7.2] What is an object? A storage area with related semantics is called an object.
When you define a variable INT i, we say "I is an object of type INT". In object-oriented, "object" is usually referred to as an instance of the class. " Such a class defines a possible behavior of many instance objects of such classes.
[7.3] When is the interface is "good"? When it provides a simplified view of a large pile, it is "good" when it can use a user's vocabulary. "A large pile" is usually one or a group of closely associated classes, "users" refers to other developers, not end users. Simplified views are unnecessary detail content being intentionally hidden. This reduces the chance of user error. The user's vocabulary means that the user does not need to learn new words or concepts. This reduces the detail of the user to understand it.
[7.4] What is package? In order to prevent unauthenticated access to some information and functions.
The key idea of packaging is to separate unstable blocks in the software from a stable block. The package covers the software block on a firewall, which prevents software from other blocks from accessing unstable blocks, which can only access stable parts. This prevents it from working properly after the unstable portion is changed. In object-oriented, "block" (CHUNK) is usually referring to a class that is closely associated with a group.
Unstable part refers to the details of the realization. If the block is a single class, unstable portions typically package with private and protected. If it is a block of closely associated classes, packages can be used to prevent complete access to this group. Inheritance can also be seen as a form of package.
The stable portion refers to the interface part. A good interface can provide a simplified view with the user's vocabulary, and it is designed by the outside ("user" refers to another developer, not the final purchase user "). If it is a single class Block, this interface is this class's public section: member functions and friends functions. If it is a group of blocks, the interface will include multiple classes in the block.
Design a clear interface and separate the interface from the implementation is just to allow users to use these interfaces, but the process implemented by the package interface is to force users to use these interfaces.
[7.5] How to balance security and availability (ease of use)? In C, the package is implemented by making members a static in a set of units or modules. It prevents other modules from accessing static content. (By the way, this approach is already unappledged, don't do this in C .)
Unfortunately, you can reach multiple instances and packages through a class. Public: is a part of a class containing classes, which is usually composed of classes: member functions and its friends functions. Private: is part of the implementation of the class in the class, which is where data is present. The final result is like a "packaged structure". This reduces safety (information hide) and availability (multiple instances).
[7.6] How do I have unstable packages in other programmers to see my private part of my class? Don't use it so much - the package is for the code, not for people.
Other programmers see your private or protected members will not cause your packaging unstable, as long as they do not write other code according to the content they see. In other words, the package cannot prevent people from knowing the content in a class, which can only prevent the code from writing independently with the inside of the class. You don't need to spend "maintenance costs" to maintain the gray white things between your two ear, but you have to spend "maintenance costs" to maintain the code written from your hands. What you can know is not to increase the cost of maintenance, write some code that depends on the interface rather than relying on its implementation process.
In addition, this is often not a problem. I don't know which programmer will deliberately write code to access a class of private members. "My suggestion is in this case, replace it, not change code" [James Kanze]
[7.7] Is the package a security measures? Do not. Package! = Safety package is just to prevent errors, not the spy used to check security issues.
[7.8] What is the difference between STRUCT keywords and Class keywords? Struct members and basic classes are PUBLIC types in the default, but they are private by default when they are in the class. Note: You should make your base include clear public, private, protected, rather than dependent on the default. In addition, Struct and Class are functionally identical.