24. Object Encapsulation
Yin and Yang Geography two points, the hermit is yin----"Jade Marrow Sutra."
"In Cantonese, there is a type of material and character Ah!" "Exclamation mark," this where is in the design software, is clearly in the design of the object of the right. ”
"Aren't we talking about object design?" The colon smiles and asks, "in the OOP world, every programmer is the creator." Keep warm, attentive and aesthetically appealing, and perhaps one day, like the Pigmalion of Greek mythology, the beauty of a sculpture becomes alive. ”
"Wow, that would be beautiful!" The comma is extremely exaggerated.
The class roared with laughter.
"Just mentioned abstraction is the foundation of three basic features of OOP, and we'll dissect it one after the next." "The colon quickly folded up the topic," the first is the encapsulation sex. Remember when we talked about the object paradigm, the quotes tried to explain the encapsulation to us, but I was brutally interrupted. Now let's ask him to continue the lecture. ”
In the crowd's teaser applause, the quotation marks are somewhat shy: "Encapsulation is the packaging of data and related behavior to achieve information hiding." ”
"Almost unassailable." "The colon is a bit conservative," then is there a difference between encapsulation (encapsulation) and information hiding (information hiding)? ”
"It should be one thing." "Under the stare of the colon, the quotes hesitated," Um ... Information hiding is a principle, and encapsulation is a way to achieve this principle. ”
Clinches "The colon is a very good compliment," although most reference books do not distinguish between the two, I would like to parse them. In fact, the broad package is just a package, that is, package or bundle, is sealed but can be transparent. Or, encapsulation means putting some data and methods in a closed box--either a black box or a white box. Syntactically, this is the biggest difference between OOP and procedural languages such as C. What effect does this bring? ”
The period reacts quickly: "This is tantamount to introducing a new modular mechanism that binds the relevant data and the operations on it together to form a module called a class." ”
"The answer is correct!" "Colon is satisfied," we used C to implement the queue, but because C does not support encapsulation, only in the form of files to partition modules, obviously not as convenient and clear as class division. In addition, the encapsulation also has the grammatical sugar (syntactic sugar) effect. ”
Question mark curiously asked: "What is the grammatical sugar?" Isn't it sweet? ”
"The so-called grammatical sugar, is some of the grammatical sweetness." It's not a core syntax, and it doesn't offer any extra functionality, but it's more concise, practical, more natural, more cool and more flashy. "The colon is intended to fill the generation gap with fashionable words," We know, using the form of a predicate (subject, object), while OOP takes the form of a subject. Predicate (object). ”
"Oh, that dog eats excrement and eats dog excrement, that is not sweet." "Comma again to gag."
The crowd laughed their heads off.
The colon unmoved: "Take the queue for example, if you add a queue member, with just the C implementation, we need to write down: Queue_add (queue, item)." If you use Java to achieve, just write Queue.add (item). Because encapsulation enables add to bind to a queue, one can put object queue forward, which is more consistent with natural language and less typing; on the other hand, this binding causes add to be restricted to the queue class, so it is not necessary to prefix the ' queue_ ' with the method function name of other classes. This also saves typing and makes the interface simpler. ”
"If C supports function overloading (overload), the prefix of ' queue_ ' can be omitted," the period suggests. ”
"What you say is neither right nor wrong." "The colon is dialectically judged," If C supports overloading, the prefix does, but from another perspective, even if Java or C + + does not support overloading, the prefix can be omitted with a sample. Because the function add is no longer a global function, the queue class is its context. In other words, functions that belong to different classes are not likely to produce ambiguity (ambiguity), even if their signatures (signature) are exactly the same. So we're going to take credit for the encapsulated name. ”
Full stop.