473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Separated Interface in practice

Hi All,

I'm having a problem implementing the Separated Interface pattern from
Martin Fowler's book Patterns of Enterprise Application Architecture.
I'm using C# in Visual Studio 2005.

The problem I'm trying to solve is one of validation. Let's say I'm
building a book store application and I have a Genre object in my
Domain Model. When I'm adding a new genre, I want to validate the new
object to make sure that a genre with the same name does not already
exist. Naturally, I make a call to the Data Mapper asking for all
genre objects with the given name and see if any are returned.

This is where I encounter my problem. All of the layers in my
application are in their own assemblies (projects). The Data Mapper
already relies on the Domain Model because those are the objects that
it takes as parameters and returns from its methods. Therefore, I
cannot add a reference from the Domain Model to Data Mapper because it
would create a circular reference.

In the Data Mapper chapter of Patterns of Enterprise Application
Architecture, Fowler says the following:

"On occasion you may need the domain objects to invoke find methods on
the Data Mapper. However, I've found that with a good Lazy Load (200)
you can completely avoid this. For simpler applications, though, may
not be worth trying to manage everything with associations and Lazy
Load (200). Still, you don't want to add a dependency from your domain
objects to your Data Mapper.

You can solve this dilemma by using Separated Interface (476). Put any
find methods needed by the domain code into an interface class that you
can place in the domain package."

I understand that Fowler's first suggestion is to use a good Lazy Load,
but it is not a scalable solution to load every genre object just to
see if one exists with a given property.

So I then moved on to try and implement it using the Separated
Interface pattern. I created a data access interface my Domain Model
that my Data Mapper implements, just like Fowler suggests. The problem
is that I can't create an instance of my Data Mapper class (declared as
the Domain Model's data access interface.) I tried putting a factory
class in a separate project, but again ran in to the same problem
because that package would have to reference the Domain Model (because
the return types from the interface methods are domain objects) and
would also have to reference the Data Mapper (to create an instance of
the class.) Again, I've created a circular dependency.

I am sure that I'm not the first person to encounter this problem, any
help would be greatly appreciated!

Thanks,
Matt

Jul 11 '06 #1
2 3355
Hi Stefan,

I had the same problem a while ago, and I solved it using the
AppDomain.CreateInstanceFromAndUnWrap mathod to instantiate an object from an
assembly without needing a reference to that assembly.

I don't have an example to show it (it was at my previous employer), but it
was not too difficult.

Hope this helps,

Joris
"st**********@gmail.com" wrote:
Hi All,

I'm having a problem implementing the Separated Interface pattern from
Martin Fowler's book Patterns of Enterprise Application Architecture.
I'm using C# in Visual Studio 2005.

The problem I'm trying to solve is one of validation. Let's say I'm
building a book store application and I have a Genre object in my
Domain Model. When I'm adding a new genre, I want to validate the new
object to make sure that a genre with the same name does not already
exist. Naturally, I make a call to the Data Mapper asking for all
genre objects with the given name and see if any are returned.

This is where I encounter my problem. All of the layers in my
application are in their own assemblies (projects). The Data Mapper
already relies on the Domain Model because those are the objects that
it takes as parameters and returns from its methods. Therefore, I
cannot add a reference from the Domain Model to Data Mapper because it
would create a circular reference.

In the Data Mapper chapter of Patterns of Enterprise Application
Architecture, Fowler says the following:

"On occasion you may need the domain objects to invoke find methods on
the Data Mapper. However, I've found that with a good Lazy Load (200)
you can completely avoid this. For simpler applications, though, may
not be worth trying to manage everything with associations and Lazy
Load (200). Still, you don't want to add a dependency from your domain
objects to your Data Mapper.

You can solve this dilemma by using Separated Interface (476). Put any
find methods needed by the domain code into an interface class that you
can place in the domain package."

I understand that Fowler's first suggestion is to use a good Lazy Load,
but it is not a scalable solution to load every genre object just to
see if one exists with a given property.

So I then moved on to try and implement it using the Separated
Interface pattern. I created a data access interface my Domain Model
that my Data Mapper implements, just like Fowler suggests. The problem
is that I can't create an instance of my Data Mapper class (declared as
the Domain Model's data access interface.) I tried putting a factory
class in a separate project, but again ran in to the same problem
because that package would have to reference the Domain Model (because
the return types from the interface methods are domain objects) and
would also have to reference the Data Mapper (to create an instance of
the class.) Again, I've created a circular dependency.

I am sure that I'm not the first person to encounter this problem, any
help would be greatly appreciated!

Thanks,
Matt

Jul 12 '06 #2
First off, the best place to post problems like this is on comp.object where
Martin actually hangs out.

Second, when you interpreted the following statement incorrectly:
You can solve this dilemma by using Separated Interface (476). Put any
find methods needed by the domain code into an interface class that you
can place in the domain package."
The problem
is that I can't create an instance of my Data Mapper class (declared as
the Domain Model's data access interface.)
You have bound the data mapper to the other interfaces in the domain model.
That was not the intent. The intent was to create an independent interface,
and place it in the domain package, where both the data mapper and the
domain model can see it during compile and reference, but where other
object, needing to create a data mapper, are not making a reference to the
domain model objects.

If this doesn't make sense, repost your question to comp.object to get a
better answer. The 'big brains' in OO design and patterns hang out there.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
<st**********@gmail.comwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hi All,

I'm having a problem implementing the Separated Interface pattern from
Martin Fowler's book Patterns of Enterprise Application Architecture.
I'm using C# in Visual Studio 2005.

The problem I'm trying to solve is one of validation. Let's say I'm
building a book store application and I have a Genre object in my
Domain Model. When I'm adding a new genre, I want to validate the new
object to make sure that a genre with the same name does not already
exist. Naturally, I make a call to the Data Mapper asking for all
genre objects with the given name and see if any are returned.

This is where I encounter my problem. All of the layers in my
application are in their own assemblies (projects). The Data Mapper
already relies on the Domain Model because those are the objects that
it takes as parameters and returns from its methods. Therefore, I
cannot add a reference from the Domain Model to Data Mapper because it
would create a circular reference.

In the Data Mapper chapter of Patterns of Enterprise Application
Architecture, Fowler says the following:

"On occasion you may need the domain objects to invoke find methods on
the Data Mapper. However, I've found that with a good Lazy Load (200)
you can completely avoid this. For simpler applications, though, may
not be worth trying to manage everything with associations and Lazy
Load (200). Still, you don't want to add a dependency from your domain
objects to your Data Mapper.

You can solve this dilemma by using Separated Interface (476). Put any
find methods needed by the domain code into an interface class that you
can place in the domain package."

I understand that Fowler's first suggestion is to use a good Lazy Load,
but it is not a scalable solution to load every genre object just to
see if one exists with a given property.

So I then moved on to try and implement it using the Separated
Interface pattern. I created a data access interface my Domain Model
that my Data Mapper implements, just like Fowler suggests. The problem
is that I can't create an instance of my Data Mapper class (declared as
the Domain Model's data access interface.) I tried putting a factory
class in a separate project, but again ran in to the same problem
because that package would have to reference the Domain Model (because
the return types from the interface methods are domain objects) and
would also have to reference the Data Mapper (to create an instance of
the class.) Again, I've created a circular dependency.

I am sure that I'm not the first person to encounter this problem, any
help would be greatly appreciated!

Thanks,
Matt

Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AMB | last post by:
Hi all, I'm currently working on a large project which uses XML formatted data to communicate between all the various different systems the project ties together, apart from one, which...
3
by: Ole Olsen | last post by:
Hi Any input on what is best practice: 1 ) Put an Interface definition (e.g. IMyInterface) into a separate Assembly 2 ) Put the Interface definirion into the same assembly that holds the...
3
by: John Underwood | last post by:
Hi.. I was looking at interface, and I have a example in the docs i'll paste below.. I'm not grasping what you would gain by using a interface, does any one have a brief description of their...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
2
by: matthew_glen_evans | last post by:
Hi there, Quick one about interfaces in c#. It seems that it is illegal to declare types within an interface. I was quite used to doing this in VB.net where the interface can define a...
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out...
2
by: new2sql | last post by:
Hi there, I am not sure if this can be done entirely in SQL. Anyhow, I have the following 4 tables. TBL_Practice Practice_ID (PK) Practice_Name etc. TBL_Branch Branch_ID (PK) Practice_ID...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.