The Minimum You Need to Know About Mono and Qt by Roland Hughes - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

If you ever interview for a job programming in C++, Java, Mono, or any other OOP language and they ask you if you understand object serialization, simply get up and walk out without answering. Shops like these still exist and they shouldn't. What is the point of serialization? To store information for future use. What is the purpose of a database? To store information for future use.   When the information is in a database, other applications written in other languages can access it. When information is serialized to a file, you have to load it back into a compatible object. As you can see, shops still doing serialization are in desperate need of a qualified Systems Architect.

 

1.4  Friends and Protection

If you thought the previous discussion on structures, classes and the constants within was an eye glazer, you are really going to love this section. We brushed the topic of protection (also known as access modifiers) last section. This section will attempt to explain them better and discuss a debacle known as friends.

 

C++ tried to set the standard for access, and tried to keep it simple.   Until the creators of Qt came up with the concept of Signals and Slots, C++ protection failed miserably.

img50.png

 

If no protection was listed for a class member or method, and no protection had been specified earlier in the class definition, thdefault protection level is private It shouldn't be difficult to imagine that things got out of hand with many of the C++ class libraries.   Everything was either friend or public because you needed to get access to things the original developers kept locked away.

Let me clear up one major point of C++ confusion here:

class my_class : public some_other_class {}

The above statement does not cause only the public items to be inherited, all items will be inherited. What this does is set the minimum protection level to be applied to those inherited things. If we had chosen to say “protectedinstead of “publicall of the public members and methods would be inherited as private in my_class. All equal or higher protection levels would remain the same.

C++ is a major stickler for not allowing the downgrading of protection. If a method is declared private, you cannot derive a new class and override that method with a public version.

Java, developed some years after C++ hit the market, had the benefit of being able to see what didn't work in C++ and tried to fix such things in the Java specification. Java added an access type and dropped “friend.”  Java also tried to eliminate multiple inheritance.   Indeed, it removed the direct ability, then had to add Interfaces to the language and allow for multiple Interfaces because single level inheritance couldn't solve most of the problems developers needed to solve.

img51.png

 

I'm sure you noticed that lovely little * in the table. I wish it weren't so, but, we have to delve a bit deeper at this point. The definition generated by your JVM for your new class will contain all of the protected elements and methods from the base class, however, you cannot access the data of an instance of a base class using your new class definition.

Java got rid of pointers because the programmers working on the Java specification could never make pointers  work It  sounds cruelbuit is pretty much thtruth. Pointers got abused in C, I don't think the English language contain