vendredi 5 mai 2017

Java OO principles in practice

Recently I have been brushing on my JAVA OO principles and got looking at some questions. There was one of them I wasn't too sure about.

Task pretty much consist of designing a Java app for a corporation to help them organise Employees. So assuming that there are 5 distinctive levels in the company as:

CEO (can be only one at the time!) Vice president Director Manager Employee

My initial instinct was to write an interface for Employee with methods like 'isOnHoliday' 'monthlyPayment' etc. And then every other position would be a separate class (modeL) implementing Employee.

Is that the best solution? Or maybe Manager should implement Employee and then Director should implement Manager in a chain-like structure

Or maybe another option I thought about might be just to have an employee class with some enum in it like Employee.CEO or Employee.EMPLOYEE to differentiate between different positions.

I guess depending on the answer above, I was also considering, would it be a good practice to make CEO a singleton? As I understand correctly CEO can be only 1, so the object should be only invoked once? But is that right way to implement it? Because it doesn't really have the same function as most 'classic' singletons like a logger or task manager...

I know it's an open-ended question but I wonder how many different solutions are plausible!

P

Aucun commentaire:

Enregistrer un commentaire