tags:

views:

89

answers:

3

Following SRP and KISS principle I designed an object with properties only, but I need methods to work with the objects. What is the best way to separate entity object data and entity set object methods?

Currently I created the following objects:

Pet Entity object
Attribute Name
Attribute Age

Pet Entity Set object
List of Pet objects

Pet Engine object
Method LoadPets of Pet Entity Set
Method GetPetByName of Pet Entity
Method GetPetsByAge of Pet Entity Set

Is this the best way to design the objects?

I'm developing in .net

Thanks.

+6  A: 

You've implemented the Anemic Domain Model antipattern. Classes should implement the methods that they need, that doesn't break SRP, but IMHO SRP is way over rated anyway.

MrTelly
+4  A: 

The general idea is to keep the methods close to the data they operate on. The construct that combines data and operations is known as a class.

Seriously, why do you think it's a good idea to separate the data from the operations? That's the opposite direction to where we've been going for decades!

John Saunders
A: 

Use a functional language with support for pattern matching. Since you're on .net, F# is the obvious choice.

This works well for message oriented systems where you have mostly stateless nodes which transform messages then pass messages to other nodes. In these scenarios, you don't care about mutating the data in the message nor about the identity of message; you care about advancing the processing in each node and sending out more messages.

You're not doing object oriented design, and object oriented languages do not support this paradigm well - they tie a mutable bag of data to an object with identity, rather than creating a reactive system of message transformers.

In effect, this requires you to take the dual of the system - the messages in a reactive system correspond to the method and arguments in object oriented systems. Roughly, the state which is in the fields of the objects of an OO program is kept the call stack of a reactive program, and the state which is the call stack of the OO program is kept in the fields of the messages in the reactive program.

Pete Kirkham