Refactoring – Liskov Substitution Principle (LSP) Applied to JobMan

In the previous article I introduced 2 base classes Job and SpawnableJob. Their purpose was to forfill the closed open principle. However, as a side effect when all jobs are returned from the database spawnablejobs was also returned. This breaks the LSP as it is not intended that SpawnableJobs are substutable for Jobs and to do so would violate the single responsibility principle.

So to fix this. Spawnable will change so it has a filed of jobToBeReplicated  which will hold an instance of Job and will no longer inherit from Job.

Leave a Reply

Your email address will not be published. Required fields are marked *