Is there an object-oriented design paradigm that allows for a variable GUI and data model?

StackOverflow https://stackoverflow.com/questions/5049707

  •  15-11-2019
  •  | 
  •  

Вопрос

My dice simulator vexes me in several ways, all to do with object-oriented design:

  • the user's choice of dice test affects what should be displayed in the user interface as well as what should form part of the object representing the test data
  • the user's choice of test parameters affects what should be displayed in the user interface as well as what should form part of the object representing the test data

In other words, my GUI is variable and my data model is variable - they both depend on a number of potential conditions received in input from the user. The conventional method I have been using to handle the variation is switches and if statements, but these are confusing, bulky and nested.

Is there an object-oriented design paradigm that allows for variations in the GUI and model?

Это было полезно?

Решение

As with most problems the solution is adding more layers of abstraction :)

Have a look at MVC, MVP and MVVM*. These are patterns that are designed to separate responsibilities between UI and Data. Because you want to switch at run-time between models (data) and UI (view) you might need to create an extra abstraction, a contract, to allow any view to bind to any (or specific subset of) data.

*This link is definitly not the only source but searching the web (and of course Stack Overflow) will help you to get to grips with these patterns.

Другие советы

three most popular:

MVC if web MVP if desktop MVVM

I posted on this earlier and provided diagrams: http://carnotaurus.tumblr.com/post/2748019388/visual-pattern-links

I also suggest splitting DAL into two as well, to aid testing purposes

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top