Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are trying to abstract 2 things that is different. Is adding a <code>RentalItem</code> is same with adding a <code>MovieItem</code>? If yes then you can abstract the method. Otherwise, better not abstract it.</p> <p>EDIT: </p> <p>Maybe I am not clear with my statement. Now look at example of this code:</p> <pre><code>RentalItem rent = new RentalItem(); rent.AddItem(..params); </code></pre> <p>Is the usage of <code>AddItem</code> method in <code>RentalItem</code> class. Now for the MovieItem class:</p> <pre><code>MovieItem mv = new MovieItem(); mv.AddItem(..params); </code></pre> <p>Now looks fine. However, because <code>MovieItem</code> is inherited by <code>RentalItem</code>, we can implement it like this:</p> <pre><code>RentalItem item = new MovieItem(); item.AddItem(..params); </code></pre> <p>This comes the problem. We can see that the <code>MovieItem.AddItem</code> is different with <code>RentalItem.AddItem</code>, because it cannot be invoked by <code>RentalItem</code>, and both method accept different parameter. Now what we can do?</p> <p>First, if does not needed or if not logically same, let the <code>MovieItem</code> as a new class instead inherited from <code>RentalItem</code>.</p> <p>Second, if you need inheritance, let the <code>RentalItem</code> and <code>MovieItem</code> become only the entity with just properties and not method. And for handling the AddItem, you create another class like <code>RentalItemCollection</code> and <code>MovieItemCollection</code> which in logic does not has relation each other.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload