It's up to you to decide if IPersistent should be declared in Common or Service assembly. The best practice (usually) is to declare interfaces in a separate assembly for better layer separation. You need to take into account things like how often developers will create implementations of IPersistent, is it really need to be loose coupled, etc.
+1
A:
UserControl
2009-09-12 18:04:00
What do u mean by Service Assembly?
JMSA
2009-09-12 18:05:51
Sorry, DA in your solution.
UserControl
2009-09-12 18:08:21
Sorry again, i think my prev answer can be non-obvious. I think Common is an assembly that has no dependencies to other assemblies (your own). If it's true that means the assembly is a good candidate to host IPersistent interface.
UserControl
2009-09-12 18:14:56
Yes, DI is a common case when we're dealing with service/interface issue.
UserControl
2009-09-12 18:10:20
No, please don't. I mean, if you ask the question this way. DI means 'loose coupling' which is rarely required in real life (when used improper it adds incredible configuration hell).
UserControl
2009-09-12 18:20:35
@frogbot What? 'loose coupling' is a good design principle that should always, I repeat, always be aspired towards. Not trying to achieve loose coupling will result in highly duplicated code that is dependent on large numbers of things. This means every change you make to the system will now effect more and more classes, resulting in more and more bugs. It becomes a maintenance nightmare and quickly.
Ty
2009-09-12 18:42:38
I think you have a mix in your IPersistent interface. It seems it has at least two consumers - DA classes access data properties (like Message) and someone (which isn't shown here if it exists) consumes IPersistent.Save() because it seems no sense to consume it from DA classes. So once you separate those to responsibilities you can move on to refactoring your solution. Next you need to identify which part your are going to reuse and thus make its dependencies weak - put IPersistent interface in a separate assembly (Separated Interface principle) or put it into assembly with reusable classes.
Dzmitry Huba
2009-09-12 19:14:23
A:
IPersistence is a concern for you DA and a means for your BO to communicate through it. That relationship should end there. Your UI should only know your BO and if you need to define a new interface to support "coding to contracts" define a new one in your BO. Your UI and BO should have separate concerns for what they do within the system.
For example, the IPersistence interface is going to define specific tasks for persisting the record to the database. You don't want that in your UI because it would be bypassing your BO. So unless you want an anemic BO, which really doesn't do anything and shouldn't be there at all, define something new at that level that relates to supporting your business logic.
Ty
2009-09-12 18:46:01