Jump to content

  • Log In with Google      Sign In   
  • Create Account

Separating logic/features from data/domain

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Structural   Members   -  Reputation: 328


Posted 09 January 2013 - 11:05 AM

Hi all,


my colleagues and I are having a recurring discussion about separation of functionality/logic.

Personally my view (and perhaps I am stuck in this way of thinking) is to separate data/domain and algorithm/functionality. And I notice I'm quite a purist in that.

My colleagues on the other hand tend to put the functionality over multiple classes that I would consider "data"-classes, or domain classes.


More concretely, we are now implementing a user story that aligns images, grouped by date and image series. 

My natural tendency, first reflex, is to start making an ImageAligner class in which I'd implement that feature, using the domain/data. This would have all the "algorithmic" stuff needed for the feature, like grouping by date etc etc, including the alignment logic.

The application would then instantiate that ImageAligner and it would listen to the data/context and do its stuff.

My colleagues argue on the other hand that the ImageAligner class is not needed. They claim it would be fine to put parts of the feature into the domain objects. The feature would be implemented through the collaboration of these domain classes.

One of their other arguments is that, because my solution looks like a strategy pattern, it adds just more complexity. They would even say it's over-engineered. Whereas I find it simpler because it isolates the feature in one place, making it easier to find and modify. 


I'm having a hard time convincing them (and they me). Mainly because what I see as domain/data objects, they consider to be functionality/feature classes. Also I have had some very good experiences in the past separating logic and domain in this way, making it hard for me to let go of this pattern of thinking.

Do you strictly separate algorithms/features/logic from domain/data in separate classes?

What would be arguments for choosing the one or the other design? 

Or am I just stuck in an odd way of thinking?

Penny for your thoughts.



#2 Dan Violet Sagmiller   Members   -  Reputation: 960


Posted 09 January 2013 - 01:22 PM

I would agree with you.  In my experience, something that manipulates the data in only a way that the user will see, should not be part of the data code.  becuase you could create your code as a library of business logic, and then have the UI managed separately.  I.e.  There should be nothing about business logic that can't be tested with an application only calling on commands presented.  The UI, which I assume ImageAligner class is for, is best in the UI project, or more of a UI based layer.  MVC & MVVM both go that direction, and are fairly popular.  not an end all be all though. 


However, if your application is a stand alone app with no intention of ever upgrading to new UI technologies, then sure, throwing your UI code in with your data management is fine.  But try convincing the business side that choosing this development model is better, because it prevents us from improving our technology later.  (at least makes it more difficult.


I'm presuming I understand what you are expressing, but my apologies if not.

Moltar - "Do you even know how to use that?"

Space Ghost - “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer."

Dan - "Best Description of AI ever."

My Game(s), Warp Wars is in early development and can be found here: http://blog.WarpWars.Net.

#3 Dan Mayor   Crossbones+   -  Reputation: 1719


Posted 09 January 2013 - 02:28 PM

Not exactly sure if I follow you on this one but I think I would agree at least to a point.  It's normally my practice to take a more "entity object" related approach with static manager systems.  That is to say that things like the "Story" would be it's own object wherein it would contain the image sets, descriptions and all other pertinent data related to the "story".  The Manager object I would use would handle the logic of listing and grouping and what not (and it would be static which might help your side of the debate).  To me, it seems that your partners are concerned about the instantiation of objects that have minimal code effect on the page (which I to struggle with sometimes).  That is to say that basically they don't want to instantiate a new instance of a class just to call one function on it.  To them maybe this adds an additional layer of complexity in that you need to know when and how to instantiate this object.  This tends to come from coders more used to procedural coding wherein a function is a function and when you need to pass large argument sets you would do so as a reference or instance of some structured object (such as a struct or class).


Anyway, I don't mean to try and psycho-analyze the team or the positions.  My point here is that maybe you can meet somewhere in the middle through well designed use of data objects and static manager like systems for the logic end.  This allows you to get your way and separate the logic into it's own class object and the data into their own objects while only requiring a slight difference in the way your team members may be thinking.  From what I gather, they seem to want to just plug some more logic into existing systems to limit the lines of code needed to create a new object and call a single function on it.  You both get your way when it's static, the logic is separate and it's still only one line of code to call negating the need for instantiation.



  Not sure if this is appropriate or helpful in any way but I tried.  Hope it at least gives some ideas of compromising talks to get you all back to work.

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post


#4 Aeramor   Members   -  Reputation: 1488


Posted 09 January 2013 - 02:29 PM

I would actually agree with your colleagues given the context. Making an additional class to handle very specific functionality seems a waste of space and indeed increased complexity with no real return other than easier to 'mind map'. If, however, you were to make a generic data class, which is expanded upon to become the derived class image, then having a class which handles alignment from the generic data makes sense.

For your example though this wouldn't make a whole lot of sense because each piece will likely be very different.

An example would be in a rendering engine, sure the renderer takes care of the all the generic stuff but then your model class typically is derived from a base class that has a mandatory override function of 'render' which contains the specific logic to render itself. What you're suggesting may well need a class that handles the alignment/drawing/placement whatever of very many things which makes calling renderObjectType41(thisIsAnObject) not as pretty as you may have hoped.


CTO at Conjecture, Inc.

#5 ApochPiQ   Moderators   -  Reputation: 18361


Posted 09 January 2013 - 05:38 PM

You're both partially wrong.



Separation of concerns is good, so you're right on that front. But needless abstraction and indirection are bad, so your colleagues are correct there.


An ImageAligner object sounds like a waste of time to me. You should have a container of Images and a function which you map across that container to produce the "aligned" or grouped or whatever results that you want.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.