I know the difference between domain and application services. But can't really see the difference between methods in domain entities and domain services:/
I have a game, that has State
, Players
etc.. It also has methods like AddPlayer
, MoveLeft
, Jump
. Where these methods goes? Should I create naked KOGame
with only properties and then KOGameServices
with functionality?
Uncle Bob in his article here wrote "An entity can be an object with methods, or it can be a set of data structures and functions."
I don't even want to mention that methods like Move
or Jump
will have to be also in App Services, in KOGameAPI
- cause those methods are needed by UI (through interfaces of course).
Here is my class:
public class KOGame
{
public GameState State { get; set; }
public IList<Player> Players { get; set; }
public int PlayersCount;
public KOGame()
{
State = GameState.New;
PlayersCount = 2;
Players = new List<Player>();
}
public void AddPlayer(Player player)
{
}
public bool MoveRight(int id)
{
return false;
}
public bool MoveLeft(int id)
{
return false;
}
public bool Jump(int id)
{
return false;
}
}
So, wrap up my question: What methods goes to Domain Services and what methods goes to Domain Entities? Having for example Class1
class, when should I create Class1Services
class?
EDIT:
Just a quick explanation why I choose DDD
:
I want to create cross platform app and I want to have single layer common for every platform. I choose C#
, cause with help of Xamarin
I can easily implement single domain model and even services for every platform. I just got stuck at deciding what methods should go to Services and what as a part of entities in Domain Model
If, to acomplish a use case, you need, at domain level, coordinate 2 or more aggregates you put the coordination logic in domain services calling aggregate methods. If just one aggregate is needed then no domain service is involved. Just call aggregate method from app service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With