Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain Driven Design - External Data API as Respository or Service

In a blog application developed using domain driven design a 'Post' entity has a related collection of tag entities.

On creating the post (e.g populating the object from the UI) i would like to call a third party API via REST which takes the content of the post and extracts semantic tags (link text) for association.

Main Question : What is the best way to design this...

Is it best designed so that the Post entity would call a domain service such as PostServices.GetTags(Postcontent) passing its content and retrieving back a list of tags.?

** PostServices.GetTags would then inteface with the REST API via a further wrapper class.

Or should the third party API be wrapped as a repository?

Should the function Post.GenerateTags(), should not exist within the domain entity at all?

Further questions :

1 : I have also read that it is not good practice to have a domain entity converse with a domain service. Is this true?

2 : Is it ok to get a reference to the PostServices domain service via a factory creation method. e.g...

IPostService PostService = ServiceUtil.GetPostService(); return PostService.GetTags(Post.content);

3 : Is it acceptable to have the domain service coupled to a third party api?

4 : Should the domain entity simply just know how to deal with the tags received via the application layer which has called the REST API.

Slowly trying to get my head around DDD, however I can't seem to find any examples of how to implement this sort of thing.

like image 826
sjb101 Avatar asked Feb 16 '10 11:02

sjb101


People also ask

What is Domain Driven Design in software engineering?

Domain-driven design (DDD) advocates modeling based on the reality of business as relevant to your use cases. In the context of building applications, DDD talks about problems as domains. It describes independent problem areas as Bounded Contexts (each Bounded Context correlates to a microservice), and emphasizes a common language to talk about ...

What is DDD (Domain-Driven Design)?

Domain-driven design ( DDD) is a software design approach focusing on modelling software to match a domain according to input from that domain's experts. In terms of object-oriented programming it means that the structure and language of software code (class names, class methods, class variables) should match the business domain.

Is it possible to create a domain model from a repository?

? Domain model is not allowed to depend on repository and domain service is part of domain model -> domain service should not depend on repository. What you should do instead is assemble all your entities that are needed for business logic execution already in application service and then just provide your models with instantiated objects.

What is a service in Domain-Driven Design?

Eric Evans introduces the notion of a service as a building block within Domain-Driven Design in the blue book: When a significant process or transformation in the domain is not a natural responsibility of an ENTITY or VALUE OBJECT, add an operation to the model as standalone interface declared as a SERVICE.


1 Answers

In a Blog application, a Post is an Entity and a Tag is a value object. A Tag hasn't got identity. You should have:

  • PostsRepository
  • Post (Entity)
  • Tag (value object)

A Post has got a list of tags.

Questions:

1 : I have also read that it is not good practice to have a domain entity converse with a domain service. Is this true?

Yes, itsn't a good practice. You entity hasn't want to be coupled with a domain service. If you do that, then you couldn't reuse them later. Did you have consider to fire a domain event. You can tell your service domain do something fire domain events.

2. : Is it ok to get a reference to the PostServices domain service via a factory creation method. e.g..IPostService PostService = ServiceUtil.GetPostService(); return PostService.GetTags(Post.content);

Yes, it's possible. A factory method could return an abstract class or an interface. This is a good Software Design Principle "code to an interface not to an implementation". If you do this, you'll be able to change your implementation later and you won't have to change yout client code.

3 : Is it acceptable to have the domain service coupled to a third party api?

I don't recommend you this, but it is acceptable.

Sorry, I don't understand question 4.

Look this link. I hope it help you.

https://stackoverflow.com/questions/901462/ddd-where-is-it-most-appropriate-to-get-a-list-of-value-objects/901562#901562

like image 126
yeraycaballero Avatar answered Sep 17 '22 14:09

yeraycaballero