nav

       HOME    BINUS EVENT   HOW TO   KBP   THOUGHTS

About



Tuesday, January 20, 2015

Assignment #12

Source:
Concepts of Programming Languages, Robert W. Sebesta.
Chapter 12: Support for Object-Oriented Programming, page 570-572

By:
Name : Helena Natanael
NIM  : 1801380333




Review Question:

6. Describe a situation where dynamic binding is a great advantage over its absence.
Consider the following situation:
There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different because the subclass objects are slightly different. So, the subclass overrides the inherited draw method. If a client of A and B has a variable that is a reference to class A’s objects, that reference also could point at class B’s objects, making it a polymorphic reference. If the method draw, which is defined in both classes, is called through the polymorphic reference, the run-time system must determine, during execution, which method should be called, A’s or B’s.

7. What is a virtual method?
A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called is determined based on the object's runtime type, which is usually that of the most derived class.

8. What is an abstract method? What is an abstract class?
An abstract method is a method which all descendant classes should have. An abstract class is a class which has abstract method.

9. Describe briefly the eight design issues used in this chapter for object-oriented
languages.

  • What non-objects are in the language?
  • Are Subclasses Subtypes? If so, derived objects can be legally used wherever a parent object could be used.
  • Type Checking and Polymorphism
  • Single and Multiple Inheritance. Inherit from 1 (or more than 1) parent.
  • Object Allocation and Deallocation.  Are objects allocated from heap or stack.
  • Dynamic and Static Binding. When are messages bound to methods, before or during run-time?
  • Nested Classes. Can a class be nested inside another class?
  • Initialization of Objects. Are objects initialized when created? Implicit or explicit?

10. What is a nesting class?

A nesting class is a class defined inside another class


Problem Sets:

6. Compare the multiple inheritance of C++ with that provided by interfaces in Java.
C++ inheritance is implementation inheritance. That is, a class inheriting from two of more superclasses actually inherits the code from those classes. Java’s interface mechanism is an interface inheritance. That is, a class implementing two or more interfaces simply inherits (and must provide its own implementations for) the methods of the interface.

7. What is one programming situation where multiple inheritance has a significant advantage over interfaces?
A situation when there are two classes derived from a common parent and they have a child.

8. Explain the two problems with abstract data types that are ameliorated by inheritance.
The problems solved are reusability of code and “extensibility”. Reusability because one won’t have to copy/paste his code from one data type to another, allowing for a greater readability. Extensibility because a method can accept a certain class as an argument, and get a child class of this one. This will allow the user to have a wider set of functionality, but the method will still be able to know that the entities it relies on are present.

9. Describe the categories of changes that a subclass can make to its parent class.
Subclasses can add things (variables, methods). Subclass in C++ can effectively remove a method using "private" inheritance. Inherited methods can be overridden.

10. Explain one disadvantage of inheritance.
Disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled.
This means one cannot be used independent of each other.

No comments:

Post a Comment