I'm here at the Headstrong office, it's the second day of their boot camp. We've started conducting our completely-overhauled Java Fundamentals curriculum, where we soak them for two whole days in OOP and OOD. I just gave a quiz this morning so I'll find out if they really got the concepts. Here are some of the questions I asked:
1. (1 pt) What is the worst sin in object-oriented programming?
duplicate code
2. (1 pt) If you are experiencing “shotgun surgery”, what should you do?
• consolidate related code together
• eliminate duplicate code
3. (1 pt) If you see data clumps or are having long parameter lists, what should you do?
• consolidate the data clumps into a classes
4. (2 pts) What are the five recommended guidelines in writing a good OO program?
• The Once and Only Once Rule
• The One Responsibility Rule
• The OO Prime Directive
• The Law of Demeter
• Well-Defined Interfaces, Hidden Implementations
5. (2 pts) State the “OO Prime Directive”. Any of the three versions given will suffice.
• Never ask an object for information that you need to do something; rather, ask the object that has the information to do the work for you.”
• Ask for help, not information.
• The maintainability of a program is inversely proportional to the amount of data that flows between objects.
6. (2 pts)State the Law of Demeter in its precise form. Complete the blanks below
A method of an object should only invoke the following kinds of objects:
1. itself
2. its parameters
3. any objects it instantiates
4. its direct component objects
7. (1 pt) State the Law of Demeter in its short form:
Don’t talk to strangers .
8. (3 pts) What are the three Core Principles of OOP? Define each.
• Encapsulation
o Bundling of related data and operations
o Information hiding
• Inheritance
o Creating a class by deriving attributes and methods from another class.
• Polymorphism
o When a single data type exhibits multiple behaviors during execution.
o Dynamic binding of a data type.
o “substitutability”
o “pluggability”
9. (1 pt) In a purely Object-Oriented Language, a class is what does the work. (TRUE / FALSE)
FALSE – An object/instance does the work. A class is just a specification/design/template.
The maintainability of a program is inversely proportional to the amount of data that flows between objects.
ReplyDeleteHmm..I think I know what you mean here, but the phrasing seems like it can be improved.
For example, if a program has two objects that pass the contents of whole files or webpages between them, then that's a large "amount of data" flowing between the objects, but that doesn't really indicate anything about their maintainability.
Perhaps you are referring to the interconnectivity of the various objects? The more interconnections there are, the more difficult it is to understand and maintain the program. (Forgetting for the moment that OO is supposed to insulate us from this problem).
Question No. 10 (5 pts). Discuss instances when otherwise good OOP/OOD principles have to be broken.
ReplyDelete