Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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.

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/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/ where you might have a look at embedded controllers etc.

Micha.

You are looking at a professional application programming. I searched for tips and tricks a long time, without success. Unfortunately you will not find anything useful, it is a complicated topic and only with many years of experience you will be able to understand how to write efficiently an application. For example, almost every program opens a file, extracts information, shows it in different forms, allow processing, saving, ... but nobody explains exactly what the good strategy is and so on. Further, if you are writing a big application, you need to look at some strategies to reduce your compilation time (otherwise you will wait hours at every compilation). Impls idioms in C++ help you for example. And then there is a lot more. For this reason software developers are well paid and there are so many jobs :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top