Is it ok to have an empty subclass that extends an abstract class?

Viewed 2946

Consider the following:

  public abstract class Item {
     String name;
     String description;
     //concrete getters and setters follow
  }

   public class InventoryItem extends Item {
     //empty subclass of Item 
   }

  public class CartItem extends Item {
     int quantity;
     int tax;
     //getters and setters for quantity and tax follow
  }

InventoryItem represents an item that is available for sale whereas CartItem represents an item that is added to the cart so it has additional properties such as quantity and tax. Is it alright to have an empty subclass of the abstract class Item in this scenario?

Option 2 : We could have an empty Item interface. InventoryItem will implement Item and define name and description properties and have getters and setters. CartItem will extend from InventoryItem and will define quantity and tax as properties and have getters and setters.

Option 3 : Would it be better to have an Item interface. InventoryItem would implement Item. We could then have a CartItem class that 'has-an' Item and two properties namely tax and quantity

2 Answers
Related