mercredi 14 mars 2018

Design pattern for applying a set functions based on the type of data entity

Example: I have different types of employees in office:

  • Software engineers
  • HR
  • Sales
  • Marketing

I need to do a bunch of operations on the data of employees:

  • Assess year-end performance and give a rating
  • Based on rating, calculate performance bonus
  • Based on rating, calculate salary hike percentage
  • Issue bonus in next pay
  • Update salary based on hike percentage
  • Send out emails about rating, performance bonus and hike to employees

Problem:

  • The operations mentioned above will differ from the type of employee it is operating on(e.g. calculate performance rating for s/w engineer will be different compared to that of marketing person).
  • Some operations can be same while same may be enhancement to other operations(e.g. update salary based on hike percentage for software engineer will be same as that for sales person).
  • In future there can be addition of new set of employees and a new set of operations need to be written.

My Approach:

  • I have a driver class which has a list of operations and the employeeData.
  • A method in Driver called executeOperations calls the operations in the list one by one on the data.
  • The driver class will be initialised to an object by my main class depending on the type of employee data I am dealing with and the object will contain list of operations relevant to the type of employee data selected from a repository of functions.

What should be a good way to tackle this kind of problem?

Aucun commentaire:

Enregistrer un commentaire