I have one abstract clas开发者_如何学Cs and many child classes. In child classes are from 2 to 20 members which must be filled by user. What the best way to do this using OOP? Make form for each child class? Or hide and unhide many input elements and labels? Is there some best way? I using WPF and C#
The answer depends on what it is that your app actually does. UI should be be designed with the user in mind, not with the underlying data structure. The user probably doesn't know what the underlying data structures are, and probably doesn't care. The UI should be implemented in the way that makes it easiest for a user to use. (This is rarely a simple task.)
It's not a good practice to tightly couple the UI to the data. There are several architectures you can employ to make sure the UI and data stay decoupled: MVC, MVP, MVVM, etc.
http://en.wikipedia.org/wiki/Model-View-Controller
http://en.wikipedia.org/wiki/Model_View_Presenter
http://en.wikipedia.org/wiki/Model_View_ViewModel
A more specific answer to your question, using one of the above architectures, you'll probably want a "form" (typically called a "view") for each class.
All the members which are shared amongst all classes should be placed in the abstract base class.
We do need some more info though. Are the members totally different/dynamic? Why should there be separate forms for each child class?
If the user actions for the forms are similar, it would be nice to have one intelligent form that can handle all child classes. You only need to specify which members are visible/editable in which child class...
精彩评论