Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternative to Strategy Pattern

 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to apply OO principles in some of the project that I am working right now.
But I am not sure if this is correct.

For some readings on the net about OO principles, I always see that 'You should encapsulate what varies'.

I try to apply it in what I am working right and its about how to draw the UI of my apps.

Say, I notice that the way UI are being drawn is what varies in my apps so I created this interface.



and in my Concrete class I have an instance variable referring to this.



Now, I have this class implements the transaction



Now, I am a bit confused about the instantiation of the class. Dont you think, my hierarchy is not good? Because I need to hard code the class to be instantiated and I cannot protect this class from further change.

I am not sure, but I think what I am doing is what they call as Strategy Pattern. Though I have not done much reading about design patterns.
I think this class is still volatile to change. Could you comment on this?

 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only issue I could see here is creating the instance of concrete class should be moved outside, I guess you can use factory pattern.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic