Maybe I should ask the question in a different way. in light of ammoQ's comment, I realize that I've done something like suggested which is kind of a fix and it is fine by me.

But I still want to learn for the future, so that if I develop new code for operations similar to this, I can design it correctly from the start.

So, if I got the following characteristics:

  • The relevant input is composed from data which is connected to
    several different business objects

  • All the input data is validated and cross-checked

  • Attempts are made in order to insert the data to the DB

  • All this is just a single operation from Business side prospective, meaning all of the cross checking and validations are just side effects.

I can't think of any other way but some sort of Operator/Coordinator kind of Object which activates the entire procedure, but then I fall into a Functional-Decomposition kind of code. so is there a better way in doing this?

Original Question

In our system we have many complex operations which involve many validations and DB activities.

One of the main Business functionality could have been designed better. In short, there were no separation of layers, and the code would only work from the scenario in which it was first designed at, and now there were more scenarios (like requests from an API or from other devices)

So I had to redesign.

I found myself moving all the DB code to objects which acts like Business to DB objects, and I've put all the business logic in an Operator kind of a class, which I've implemented like this:

First, I created an object which will hold all the information needed for the operation let's call it InformationObject.

Then I created an OperatorObject which will take the InformationObject as a parameter and act on it.

The OperatorObject should activate different objects and validate or check for existence or any scenario in which the business logic is compromised and then make the operation according to the information on the InformationObject.

So my question is - Is this kind of implementation correct?

PS, this Operator only works on a single Business-wise Operation.

  • 2
    Does it work for you? Does it fulfill the business requirements? Can you extend it as required? Does it produce the correct results? If the answers to all of these are yes, then yes, the implementation is correct.
    – Oded
    Nov 24 '11 at 7:32
  • 2
  • @Oded : I'm pretty certain that my predecessor thought that the former design was good as well, but it wasn't, So.. I'm sure there are Best Practices about this, and in this question I wanted to know if I'm breaking them or not.
    – Mithir
    Nov 24 '11 at 8:02
  • 1
    Best practices are very difficult to define, especially when it comes to architecture, as every system is different.
    – Oded
    Nov 24 '11 at 9:39

If you want to restructure you code and expect further enhancements, you would apply domain driven design with N-layered approach.
microsoft architectue

The approach you applied is not object oriented, but procedual style, you use info classes to maintain the data and all the business logics are in another class. It is fine if you are not stricly following the OOP design, but it is advisible to have both data and behaviour in a single class so that you can elaborate with other OOP features like encapsulation, polymophism etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.