4

I'm building a web-app for a licensing service. My domain models are Licenses, and they can be of two types at the moment: server and client license. They are almost same, except server license has softwareId field, and client license has hardwareIdArray (client licenses can be registered to multiple clients).

So, I have a base model License with it's children: ClientLicense and ServerLicense, which bring additional fields.

Models of each type are fetched by respective Repositories (I'm using TYPO3 Extbase framework, where it is standard and recommended way).

Now comes the interesting part: each license has some additional info, which I can't persist (well, I can, but only in temp cache), but instead should fetch it from REST service (e.g. "expirationDate", which may be changed outside of my web-app). And for each type of license this additional info may be different and may be fetched by different method in REST api. Also each license type has different activate() REST method. At same time there are common REST methods, like getLicenseFile().

So, I decided to hide all this internal stuff under LicenseService class, which is recommended to communicate by Controllers or other classes, that need some license info. LicenseService itself communicates to LicenseRestApi, which contains some low-level functionality to perform REST requests.

And here comes a question: who should know about each license type specific functionality? F.e. when a controller asks a service to getAllLicenses($user), is it a Service, who should determine a type of license and then perform calls to respective Repository and appropriate methods in RestApi; or a license should know everything about itself and call RestApi; or some new classes, like ClientLicenseProcessor and ServerLicenseProcessor, to which should LicenseService communicate and all the communication with RestApi should be within these processors, so in this case LicenseService will act as FactoryMethod for creating appropriate processor?

My goal is to hold specific type logic in one place and not spread it between several classes.

1 Answer 1

4

The service shouldn't make any decisions or you end up with a anemic domain model. Your license aggregate should make the decisions. If the license aggregate needs to call a web service you pass an instance of a helper for that service to the method on the aggregate. It can them choose to use them if it so wishes.

3
  • So, basicaly ClientLicense->activate(LicenseApi $licenseApi) is the correct way to do this? And when I want to fetch all licenses (server and client as well) should I call generic LicenseRepository, which should return me not License, but ClientLicense and ServerLicense objects? Aug 21, 2015 at 12:24
  • 1
    Normally you would have two repositories for the two types of licenses but other than that it sounds reasonable. Aug 21, 2015 at 12:44
  • Domain Driven Design embodies to s philosophy if you like buzz words. Aug 21, 2015 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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