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 2 3364
Hi Stefan,
I had the same problem a while ago, and I solved it using the
AppDomain.Creat eInstanceFromAn dUnWrap 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**********@g mail.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
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**********@g mail.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 communicates via space separated
list.
Obviously, having a space separated list floating around isn't
desirable (it doesn't even support spaces in the data, for one), but I
can't think of a killer reason to convince the owner of that system to
|
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
concreate and implementing class?
MS seems to like the first approach with 2 assemblies over the latter with
just one assembly?
|
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 benefit?
Thanks,
John Underwood
|
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. The User Experience, or how
the user experiences the end product, is the key to acceptance. And that is
where User Interface Design enters the design process. While product
engineers focus on the technology, usability specialists focus on the user...
|
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 interface and accessing the
datastore MUST pass in a UserToken in the constructor of the object.
Is this not possible?
Am I forced to add the UserToken as a property on the object instead?
/Ole
| |
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 by Sets.
- ICollection cannot decide containment
- IList promises indexability by the natural numbers, which is not
achievable (since i hash elements, not sort them).
- IDictionary is definatly not setlike.
Although I can, of course, define...
|
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
clients remoting interface and object model.
eg..
|
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 because I have written a generic plugin system for my
current and future C# needs. I defined a base plugin system interface named
IPlugin (original, I know...) which contains some basic plugin infomration
all plugins of this system must expose...
|
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 (FK)
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |