Skip to content

Instantly share code, notes, and snippets.

@DavidGinzberg
Created November 11, 2015 15:22
Show Gist options
  • Save DavidGinzberg/4a17af48e22cd0520363 to your computer and use it in GitHub Desktop.
Save DavidGinzberg/4a17af48e22cd0520363 to your computer and use it in GitHub Desktop.
Design pattern labs

Factory Method pattern

Employee factory:

— Write an abstract Employee class with name, type, and payment attributes (and corresponding accessor functions).

  • Extend Employee with at least two child classes that represent types of employees (e.g.: salaried, hourly, contract, permanent, etc)
  • Create an EmployeeFactory class with a makeEmployee method that takes two Strings (employee name and employee type) and returns an Employee object constructed from the corresponding child class based on the type parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment