views:

881

answers:

8

I'm looking for patterns that concern coding parts of a GUI. Not as global as MVC, that I'm quite familiar with, but patterns and good ideas and best practices concerning single controls and inputs.

Let say I want to make a control that display some objects that may overlap. Now if I click on an object, I need to find out what to do (Just finding the object I can do in several ways, such as an quad-tree and Z-order, thats not the problem). And also I might hold down a modifier key, or some object is active from the beginning, making the selection or whatever a bit more complicated. Should I have an object instance representing a screen object, handle the user-action when clicked, or a master class. etc.. What kind of patterns or solutions are there for problems like this?

+5  A: 

I think to be honest you a better just boning up on your standard design patterns and applying them to the individual problems that you face in developing your UI.

While there are common UI "themes" (such as dealing with modifier keys) the actual implementation may vary widely.

I have O'Reilly's Head First Design Patterns and The Poster, which I have found invaluable!

Shameless Plug : These links are using my associates ID.

Rob Cooper
Head First Design Patterns is a great book, though I did laugh about this - http://fishbowl.pastiche.org/2005/08/12/the_head_first_girls_double_life/
David
I akso have "Head First Design Patterns". I found it really good to learn basic patterns in a funny way.
FrenchData
HFDP is now on my Amazon wish list...for when I finish Jon Skeet's "What I need to master C#" ;)
dboarman
+1  A: 

I don't think the that benefit of design patterns come from trying to find a design pattern to fit a problem. You can however use some heuristics to help clean up your design in this quite a bit, like keeping the UI as decoupled as possible from the rest of the objects in your system.

There is a pattern that might help out in this case, the Observer Pattern.

Antonio Haley
A: 

Rob: I have gone through the standard 20 or so patterns that I could find, and possibly help out. But a lot of times, these don't help me out much in making a easy to overlook solution to the gui related problems. Since I do a lot of different types gui coding, any pattern that someone found to be useful, or related to guis, is of interest. Thanks for the answer, I'll be sure to get a look at that book (... with that girl on the cover. Jesus she must be smart, making her way on to that cover :) )

Antonio: The Observer is great, but it don't really help me make out a nice way of figuring out which item to make an action on (drag the already selected, or select a new, things like that) (for instance). Decoupled or not, I still have to have objects representing items displayed, and somewhere I have to handle the interaction logic. Thanks for the answer anyhow. I guess you have more experience from this than me, so I take your advice and go see what I can find.

Peteter
Not an answer. Use comments instead.
Smasher
A: 

Rob: You should be awarded a speedy badge for writing an accepted answer within 30 min or the original answer. Doesn't seem to work?

Peteter
Not an answer. Use comments instead.
Smasher
A: 

Hi Peter,

Oh wow, yeah! Thanks, I'll keep an eye out for my speedy badge.

As to the future problems, although it sucks you will have to face them, its great because thats what StackOverflow is all about! If you get to a point in UI design where you are unsure of patterns to apply/take a step forward. Then get asking my friend! I would really like to get my brain involved so look forward to it! ^_^

Rob Cooper
Not an answer. Use comments instead.
Smasher
Thanks for commenting on an answer that was created over a year ago (when I think SO may have still been in private beta). This was also before a lot of the "rules" were solidified. But I am sure the community really appreciates your useful comment. #fail
Rob Cooper
Haha! Rob I concur to some degree, but it seams SO is also about tidying up and removing old errors. :-)
Peteter
+1  A: 

Hi Peter, perhaps you're looking for something like the 'MouseTrap' which I saw in some articles on codeproject (search for UI Platform)?

I also found this series very useful http://codebetter.com/blogs/jeremy.miller/archive/tags/Design+Patterns/Build+your+own+CAB/default.aspx where you might have a look at embedded controllers etc.

Micha.

Micha
+1  A: 

I know you said not as global as MVC, but there are some variations on MVC - specifically HMVC and PAC - which I think can answer questions such as the ones you pose.

Other than that, try to write new code "in the spirit" of existing patterns even if you don't apply them directly.

Draemon
+1  A: 

Object-Oriented Design and Patterns by Cay Horstmann has a chapter entitled "Patterns and GUI Programming". In that chapter, Horstmann touches on the following patterns:

  • Observer Layout Managers and the
  • Strategy Pattern Components,
  • Containers, and the Composite Pattern
  • Scroll Bars and the Decorator Pattern
DTS