One factor I see in certain DDD enterprise applications which i focus on, is using connects which are just like the domain organizations, having a one-to-one mapping of qualities and processes. Indeed a website object is definitely used through it's one-to-one interface, and all sorts of domain organizations possess a one-to-one interface in this fashion.
Domain object Account:
public class Account : IAccount Title //...more fields which are also in IAccount public decimal Balance
And it is matching interface
public interface IAccount Title //... all of the fields in Account decimal Balance
But recently I have become progressively believing that this really is, actually, an anti-pattern.
I went it by some designers on view source community, plus they state that this is dependant on design mistakes or defects, somewhere in the chain of design.
And So I tell my co-workers they should quit creating connects for that Domain objects. Because there's no purpose for them, and you've got to update the interface if you update the domain organizations.
First the claim is made these connects provide 'decoupling', however i counter that since the connects possess a one-to-one relationship using the domain organizations that they don't really provide any decoupling, a big change towards the interface means a general change in the domain entity and vice-versa.
The following claim is the fact that we want the connects for testing reasons. My counter is the fact that Rhino-mocks offers the mocking and stubbing of concrete classes. However they declare that Rhino-mocks has challenge with concrete classes. I'm not sure basically buy that, even when rhino-mocks has challenge with concrete classes, that does not always mean we ought to use connects for that domain organizations.
So I am curious:
Why can you have one-to-one connects for the domain organizations?
Why don't you?
Why do a bad or good practice?
Thank you for reading through!
EDIT: I ought to observe that I personally use connects constantly, but when it's known as for I'll make use of an interface in the drop of the hat. But I am particularly mentioning to domain organizations with one-to-one connects.
It is a bad practice as referred to, but...
There is no specific reason why your connects have to be diverse from your domain organizations sometimes it truly is the best mapping. But it is suspicious it's always the situation. The purpose of concern there's an issue of set up connects were truly designed, or whether or not they were just tossed into position from insufficient time / idleness.
To apply your example, the IAccount interface you describe exposes getters and setters around the Account object it appears just a little odd and unlikely that exactly what uses a merchant account will need to set the total amount around the account, which that implied permission is specified at this degree of interface. Can there be room in your body where you need to basically check although not set the Balance?
The greatest reason behind always indicating the domain objects as connects rather than directly as classes is to provide you with a diploma of freedom around the implementation. Inside your example you simply have one type of IAccount, therefore it is just a little redunant.
But what should you have had, for instance:
public class Account : IAccount // Usual account, persistent public class MockAccount : IAccount // Test mock object public class TransAccount : IAccount // Account, not persistent public class SimAccount : IAccount // Account inside a performance sim
and so forth?
By determining the domain objects as connects, you are able to replace the implementations without disturbing your domain definition.