Fri, May 31, 2019 4:50:35 PM

do anything else, the methods from the base-class interface come right along into the derived <br/>
class. That means objects of the derived class have not only the same type, they also have the <br/>
same behavior, which isn�t particularly interesting. <br/>
You have two ways to differentiate your new derived class from the original base class. The <br/>
first is quite straightforward: You simply add brand new methods to the derived class. These <br/>
new methods are not part of the base-class interface. This means that the base class simply <br/>
didn�t do as much as you wanted it to, so you added more methods. This simple and primitive <br/>
use for inheritance is, at times, the perfect solution to your problem. However, you should <br/>
look closely for the possibility that your base class might also need these additional methods. <br/>
This process of discovery and iteration of your design happens regularly in object-oriented <br/>
programming. <br/>
<br/>
Although inheritance may sometimes imply (especially in Java, where the keyword for <br/>
inheritance is extends) that you are going to add new methods to the interface, that�s not <br/>
necessarily true. The second and more important way to differentiate your new class is to <br/>
change the behavior of an existing base-class method. This is referred to as overriding that <br/>
method. <br/>
Introduction to Objects 23�<br/>
<br/>
To override a method, you simply create a new definition for the method in the derived class. <br/>
You�re saying, �I�m using the same interface method here, but I want it to do something <br/>
different for my new type.� <br/>
Is-a vs. is-like-a relationships <br/>
There�s a certain debate that can occur about inheritance: Should inheritance override only <br/>
baseclass methods (and not add new methods that aren�t in the base class)? This would mean <br/>
that the derived class is exactly the same type as the base class since it has exactly the same <br/>
interface. As a result, you can exactly substitute an object of the derived class for an object of <br/>
the base class. This can be thought of as pure substitution, and it�s often referred to as the <br/>
substitution principle. In a sense, this is the ideal way to treat inheritance. We often refer to <br/>
the relationship between the base class and derived classes in this case as an is-a <br/>
relationship, because you can say, �A circle is a shape.� A test for inheritance is to determine <br/>
whether you can state the is-a relationship about the classes and have it make sense. <br/>
There are times when you must add new interface elements to a derived type, thus extending <br/>
the interface. The new type can still be substituted for the base type, but the substitution isn�t <br/>
perfect because your new methods are not accessible from the base type. This can be <br/>
described as an islike-a relationship (my term). The new type has the interface of the old type <br/>
but it also contains other methods, so you can�t really say it�s exactly the same. For example, <br/>
consider an air conditioner. Suppose your house is wired with all the controls for cooling; <br/>
that is, it has an interface that allows you to control cooling. Imagine that the air conditioner <br/>
breaks down and you replace it with a heat pump, which can both heat and cool. The heat <br/>
pump is-like-an air conditioner, but it can do more. Because the control system of your house <br/>
is designed only to control cooling, it is restricted to communication with the cooling part of <br/>
the new object. The interface of the new object has been extended, and the existing system <br/>
doesn�t know about anything except the original interface. <br/>
24 Venkata Pilaka Venkata Pilaka <br/>

Comments

Popular posts from this blog

termux vnc viewer setup

../Settings.jpg

me.html