NavigationUser login |
OOAn empty abstract class can be usefulI've been working on a system that takes different types of things in an order. The order system is split up by the type of the thing beng ordered, which isn't very clever but historically that's the way someone wrote it so we just have to live with it, refactoring the code and data is not an option. In modelling the data for the differnet types of thing being ordered it turns out to be useful to have an empty abstract class:
abstract class AbstractOrderItem implements Model {
// Add a constructor to initialise the model
}
Now order items extend AbstractOrderItem: class CarOrderItem extends AbstractOrderItem ... class PlaneOrderItem extends AbstractOrderItem ... class TrainOrderItem extends AbstractOrderItem ... Now it you want to handle a list of OrderItems that's fine:
function paintBlue(AbstractOrderItem $item) {
$item->color='blue';
$item->save();
}
|
Recent blog posts
|