Results 1 to 4 of 4
Thread: State Design Pattern
- 07-18-2011, 07:29 PM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
State Design Pattern
I'm trying to implement the State Design Pattern in a utility I'm writing, but have come across this problem: By putting some code in a class that implements one of the states, it refers to the "main" form/class, and so I get an err msg. So to continue down this path, my State-specific class would be tightly coupled to the GUI. This doesn't seem right. Is there a common way of dealing with this?
- 07-18-2011, 09:30 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
I'm not fully understanding your question, especially without a clear example demonstrating the situation or the error message you refer to. If you are worried about things being tightly coupled, then inspect the design and think about where you could decouple using interfaces and/or abstract classes.
- 07-18-2011, 10:08 PM #3
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
I have a separate class that implements an interface which contains methods to be overridden. When this class's method is called, it accesses components on the main form (for lack of better terminology - I'm coming from the Delphi/C# and WPF world). I know this is not a good design, but wondering if I should scrap it, or is it salvageable. The err msg is that it can't resolve the JButton the code is "remotely" referencing. I could instantiate the "main form" class, perhaps, but this route seems fraught with danger to me...
- 07-19-2011, 05:05 AM #4
Similar Threads
-
A little design (pattern?) question...
By raindog308 in forum New To JavaReplies: 1Last Post: 01-26-2011, 09:12 AM -
Command design pattern
By hannes in forum AWT / SwingReplies: 10Last Post: 01-28-2010, 06:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks