Java Object Oriented Programming Example Code-2

Choices for implementing changing behavior 

  • Using Inheritance to support changing behavior 
    • Subclasses provides changing behavior 
    • Use it when changing behaviors are aligned only with subclasses 
    • Computing monthly pay for all Employee types – hourly employee and salaried employee 
  • Using Interface to support changing behavior 
    • Classes implement the interface 
    • Use it when changing behavior need to be imposed to classes that are not related via inheritance 
    • Only salaried employees and board members get bonuses 
  • Use Composition to support changing behavior 
    • Objects with changing behavior injected to the target class 
    • Use it when runtime selection of behavior is desired 
    • Use it when reuse of the behavior can be used in other classes

You must have an active subscription to download PDF and Lab Zip of this course topic.Please click the "Subscribe" button or the "Login" button if you already have an account.