Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Domain Classes or Interfaces   Message List  
Reply | Forward Message #4442 of 16690 |
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 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 :-

class Trade {
private Account account;
private Security security;
// ..
// ..
}

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.

Any help will be appreciated.

Cheers.
- Debasish






Wed Oct 25, 2006 9:44 am

ghosh.debasish
Offline Offline
Send Email Send Email

Forward
Message #4442 of 16690 |
Expand Messages Author Sort by Date

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...
ghosh.debasish
Offline Send Email
Oct 25, 2006
8:51 pm

... 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...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 26, 2006
6:10 am

Hi Sergio - What u say about interfaces is absolutely true .. Interfaces hide implementation - in fact it hides everything except the signature. Typically...
ghosh.debasish
Offline Send Email
Oct 26, 2006
8:57 am

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...
Zhiyi Zhang
zhiyi4ddd
Offline Send Email
Oct 26, 2006
11:50 pm

... <zhiyi4msft@...> wrote: interface and abstract class represent different relations between two entities(or classifiers in UML term?). For a class A to use...
m_alanliu
Offline Send Email
Oct 27, 2006
12:38 am

... Hi Debasish. ... Interfaces cannot directly express constraints, but even if abstract classes can do that, they don't guarantee at all that concrete ...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 27, 2006
11:01 pm

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...
ghosh.debasish
Offline Send Email
Oct 28, 2006
5:56 pm

... (http://www.martinfowler.com/bliki/InterfaceImplementationPair.html). ... You probably meant CGLIB in the context of your argument; without interfaces, the...
hal arnold
halarnold2000
Offline Send Email
Oct 28, 2006
8:58 pm

Sure I meant CGLIB .. :-) ... the New Yahoo.com...
ghosh.debasish
Offline Send Email
Oct 30, 2006
9:21 am

... 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...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 29, 2006
10:48 am

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. -- ...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 29, 2006
11:04 am

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. ...
ghosh.debasish
Offline Send Email
Oct 30, 2006
4:34 am

... 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...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 30, 2006
8:35 am

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...
ghosh.debasish
Offline Send Email
Oct 30, 2006
9:26 am

... 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...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 31, 2006
9:22 am

I think the term interface here is a bit confusng (dual meaning) A class itself has an interface that it exposes simply by being a class ...
gregory young
gumboismadeo...
Offline Send Email
Oct 26, 2006
6:31 am

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...
Tomas Karlsson
marcellus874
Offline Send Email
Oct 26, 2006
7:17 am

... 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...
Sergio Bossa
sergio_bossa
Offline Send Email
Oct 27, 2006
9:36 pm

Hi, I know DDD and SOA have been asked for earlier - but without reply. Does anyone has anything to add to such a thread now? /Tomas...
Tomas Karlsson
marcellus874
Offline Send Email
Oct 31, 2006
6:13 pm

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...
gregory young
gumboismadeo...
Offline Send Email
Oct 31, 2006
11:40 pm

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...
Randy Stafford
randalparker...
Offline Send Email
Nov 1, 2006
3:22 am

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")...
Dmitriy Kopylenko
dima767
Offline Send Email
Nov 1, 2006
5:12 pm

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...
Zhiyi Zhang
zhiyi4ddd
Offline Send Email
Nov 6, 2006
2:47 am

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...
Cliff Meyers
cliff.meyers
Offline Send Email
Oct 27, 2006
5:18 pm

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...
Alasdair Gilmour
alasdair_gil...
Offline Send Email
Oct 30, 2006
11:14 am

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...
Tomas Karlsson
marcellus874
Offline Send Email
Oct 30, 2006
5:46 pm

... 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...
Keith Ray
attkeithray
Offline Send Email
Oct 30, 2006
9:11 pm

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...
Tomas Karlsson
marcellus874
Offline Send Email
Oct 31, 2006
6:08 pm

... 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...
Alasdair Gilmour
alasdair_gil...
Offline Send Email
Oct 31, 2006
10:50 am
First  | < Prev  |  Last 
Advanced

Copyright 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help