Results 1 to 4 of 4
  1. #1
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default 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?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    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.

  3. #3
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by doWhile View Post
    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.
    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...

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Possibly you need to research the MVC pattern (Model View Controller) and/or callback methods.

Similar Threads

  1. A little design (pattern?) question...
    By raindog308 in forum New To Java
    Replies: 1
    Last Post: 01-26-2011, 09:12 AM
  2. Command design pattern
    By hannes in forum AWT / Swing
    Replies: 10
    Last Post: 01-28-2010, 06:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •