I have a situation, in which I would like your opinion about the best approach that I should take.

Let's consider 10 classes (obj001, obj002 etc.) all which represent some business entities, and are to be serialized with XML and sent via a WS to another server. Each of these classes is backed-up by a XSD schema (from which they were built). There are certain differences in their structure, so they cannot be treated all the same (eg. one may contain a table with values, another one only few static fields).

Now, I have to develop a desktop application (.net based, so either Winforms or WPF), with a distinct screen for each entity, and the following functionalities: Save to XML, Load from XML, Submit msg (send over WS), Generate document (filling a template), Validate object etc.

Methods like Generate document and Validation must be implemented differently due to the nature of the objects.

Currently I have a tabbed page control, and each page contains the data fields for a certain object. All the function buttons are common, docked to top, and based on the active page, they perform the corresponding action. The event flow works like this:

  switch (selected_page)
     if obj001_page then
     if obj002_page then
     else ...

I thought of the following approaches too:

  1. Create buttons on each tab page (this means I would know exactly what logic to execute. But still, they are all together.
  2. Convert the application to WPF, and build custom controls for each object, that are totally in charge of the corresponding logic and UI - a lot of redundant code!

As an example, my obj001 class, has over 20 properties (attributes), and all are binded to textboxes in the UI, so all the validations are written and performed in the MainWindow.cs class. Moving them to a separate class would mean to pass each value as a parameter to the validator, which is quite inpractical too. Maybe switching to MVVM (and making use of the WPF's data binding) is a better solution, don't you think?

Extensibility is very poor: for each new object, I have to add a new case to each function button. And the MainWindow.cs class is getting heavier and heavier.

I'm new to software engineering. Starting from scratch, what would be the right approach? What architectural or design pattern(s) should I look into? And how should I structure my classes?

Thank you!

  • 1
    What will rather change: the number of business entities or the functionality they provide? If the number of business entities change, go for an OOP approach and let your "pages" implement an interface to create your objects like obj001_page.createObj(). You then don't have to use switch, but you can use a generic page-object to create its corresponding business entity. If the functionality of the entities change, stay with the switch - it will not change often. If both the number of entities and their functionality changes often, this is a case of the expression problem -> google
    – valenterry
    Feb 17, 2015 at 13:05
  • 1
    Get fancy and use the XSD to generate the UIs for each business entity! SO discusses it here
    – gbjbaanb
    Feb 17, 2015 at 13:07
  • Are you sure the XSD isn't generated by WCF? If so, why not simply generate a service proxy with all associated entities? Or, alternatively, if the entities are declared in a separate assembly, could you share that assembly between the server and client and simply reuse the types?
    – MetaFight
    Feb 17, 2015 at 13:14
  • @valenterry: the functionality stays the same. the entities will change though, to be more specific, new ones might be created. For the OOP approach, let's take a simple case. I have the obj001 (AuctionRef, AuctionDate, BidAmt). Each field has a corresponding TextBox. How should I handle the validation? Either in the button listener, when pressed, check each field or have a method obj001.ValidateMe(...) and pass the value of each textbox? I want the solution to be as clean as possible.
    – ddaniel
    Feb 17, 2015 at 13:47
  • @MetaFight: Sadly, no, I cannot use proxy because there is a generic method SubmitMessage, that receives an XML string - not the best option I know, but this is what we received...
    – ddaniel
    Feb 17, 2015 at 13:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.