Here is a practical dilemma that I face when doing DDD. In my domain
model, I should have intention-revealing-interfaces - right ? This is
what DDD suggests. I assume that the term "interfaces" is not to be
taken literally as an *interface* in Java. It can be an interface or
an abstract class. Now, we all know that interfaces allow users to
provide multiple implementations and are also used to implement
multiple inheritance.
While doing domain modeling in Java, should I have Java interfaces for
the domain abstractions ? My personal view is that unless there is a
strong enough reason (like necessity to implement multiple
inheritance), we should use abstract classes as the contract. The
reason for this, I feel is that interfaces in Java only consist of
method signatures - they do not have any other constraints or
invariants specified. Hence if I provide an interface IAccount, how
can I be sure that the implementation instance that I receive during
runtime honors all the constraints that all accounts should have.
But OTOH, classes are not test-friendly. If I had interfaces, I can
easily supply mock implementations for unit testing. Take the
following example :-
Here we have a domain abstraction that contains nested instances of
other domain abstractions. If all of them are classes, then how do I
unit test ? Or am I supposed to do unit testing of Trade with actual
implementations of Account and Security abstractions ?
Here I am assuming that all my services (data access, LDAP access
etc.) are exposed as interfaces and I have mock implementations for
each of them. But I am not very much convinced about domain abstractions.
Hi - Here is a practical dilemma that I face when doing DDD. In my domain model, I should have intention-revealing-interfaces - right ? This is what DDD...
... Yes, sure. ... What you say is true, but the use of pure Java interfaces is invaluable because it gives you several advantages: * It completely hides...
Hi Sergio - What u say about interfaces is absolutely true .. Interfaces hide implementation - in fact it hides everything except the signature. Typically...
I agree that interface has values, but not much for domain objects. I'd just use class (interface + implementation) instead. That said, I don't think it makes...
... <zhiyi4msft@...> wrote: interface and abstract class represent different relations between two entities(or classifiers in UML term?). For a class A to use...
... Hi Debasish. ... Interfaces cannot directly express constraints, but even if abstract classes can do that, they don't guarantee at all that concrete ...
Hi Sergio - I fully agree with you that interfaces have lots of plus in api design. However, can u please let us know ur observations on the following aspects...
... (http://www.martinfowler.com/bliki/InterfaceImplementationPair.html). ... You probably meant CGLIB in the context of your argument; without interfaces, the...
... Hi Debasish, here are my comments. ... And I am one of them ;) I always try to use my domain objects as much as possible through all layers. ... I'm sorry...
Very interesting discussion indeed. I'd like to hear more opinions and experiences, hoping that some "guru" will spend his/her cents ;) Cheers! Sergio B. -- ...
Hi Sergio - The following are some more of my thoughts on this .. sorry for rumbling too much, but I want to get the thoughts of the experts on this matter. ...
... Don't worry, this discussion is very nice and interesting. ... I think that when you see "clients" you mean "implementors." Well, if you have more...
Hi Sergio - Just can't get off the topis .. It is interesting .. My couple of INRs .. Cheers. - Debasish ... If I have *only* interfaces and multiple...
... I know what you say. We take interfaces from two different point of view, so we have different approaches. I can't say if one is absolutely better than the...
Hi, This was an interesting discussion, and I also found Sergio’s reply interesting. The reason is that I often prefer the other solution with classes (and...
... Hi Tomas. This was an interesting discussion, and I also found Sergio's reply ... Yes, I know of several people arguing that. I fully understand the point...
I would consider the two to be completely orthogonal. ... -- If knowledge can create problems, it is not through ignorance that we can solve them. Isaac Asimov...
In one sense I view them as complementary architectural styles, in that there can be a DDD-style implementation behind a service interface. I' ve actually...
I just want to express my opinion about that (SOA and DDD). I view SOA simply as the way to "integrate" systems (subsystems or even perhaps "bounded contexts")...
I don't suppose I could define SOA. Anyone has his own favorite view. But let's look at what SOA tries to solve. The top two in my list: - Integrate systems...
You can do both: write an interface that describes the contract, then have your abstract class implement that interface and add the constraint logic to the...
I tend to come down on Martin Fowler's side of the fence on this one. I don't like splitting _everything_ into interfaces and implementations because it leads...
Hi, I agree: test should not dictate the design. If you have to do “strange things” in a class to allow test, (with few exceptions) I would say there is a...
... Actually, I think a test should influence the design. In fact, with TDD, it should drive the design. Eric recommended TDD in the DDD book. ... I would say...
Hi, I agree that if you have problems in testing, that is an indication of problem in your design. When I talked about “problem in your test setup”, I was...
... it should drive the design. Eric recommended TDD in the DDD book. I don't disagree, but I don't think that you should jump through hoops in pursuit of some...