Question on refactoring and code design

Posted by Software Engeneering Learner on Programmers See other posts from Programmers or by Software Engeneering Learner
Published on 2012-11-15T15:11:03Z Indexed on 2012/11/15 17:22 UTC
Read the original article Hit count: 484

Suppose, I have a class with a constant static final field. Then I want in certain situations that field to be different. It still can be final, because it should be initialized in constructor. My question is, what strategy I should use:

  1. add this field value into the constructor
  2. create 2 subclasses, replace original field usage with some protected method and override it in subclasses
  3. Or create some composite class that will held instance of my class inside and somehow change that value?

Which approach should I use and why?

© Programmers or respective owner

Related posts about java

Related posts about design-patterns