Aah. All I meant was that I wouldn't be able to write
Dim c1 As New IClass1
To instantiate I would need to have a reference to the 'assembly' (good,
eh?) containing Class1.
Yes, I would be interested to see an example of the Domain Model / Data
Mapper scenario, if it's not too much trouble.
Charles
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:%23r6qADXSEHA.4028@TK2MSFTNGP09.phx.gbl...[color=blue]
> Charles,
> Earlier in this thread you replied to solex with:[color=green]
> > Thanks for the time you have obviously spent understanding what I am[/color]
> trying[color=green]
> > to do. I have used interfaces, but what has stopped me going that extra[/color]
> bit[color=green]
> > further is the fact that I won't be able instantiate an interface. So, I
> > have settled with coupling to the library that contains the class[/color][/color]
itself.[color=blue]
>
> The "won't be able instantiate an interface" is the cause of my confusion
> (where I got the impression...).
>
> When I use the Separated Interface Pattern, I normally use the Plugin
> Pattern also.
>
http://www.martinfowler.com/eaaCatal...Interface.html
>
http://www.martinfowler.com/eaaCatalog/plugin.html
>
> I store the names of the classes that implements a specific interface in[/color]
the[color=blue]
> app.config file. I then use System.Activator.CreateInstance to create
> instances of these classes. Sometimes I simply pass the interface as a
> parameter as I show in my earlier post.
>
> For example in the Domain Model & Data Mapper scenario I mentioned[/color]
earlier,[color=blue]
> I have a custom configuration section in my app.config that identifies the
> data mapper class for a given domain class. In my framework assembly I[/color]
have[color=blue]
> a shared method that takes a domain object Type and looks up the[/color]
DataMapper[color=blue]
> type name in the app.config, uses Activator.CreateInstance to return an
> instance of the class that implements IDataMapper.
>
> I can post code samples this evening if you like.
>
> Hope this helps
> Jay
>
> "Charles Law" <blank@nowhere.com> wrote in message
> news:OPRh$1WSEHA.3140@tk2msftngp13.phx.gbl...[color=green]
> > Hi Jay
> >[color=darkred]
> > > I may have miss read one of your other posts, I got the impression you[/color][/color]
> did[color=green][color=darkred]
> > > not understand interfaces...[/color]
> >
> > Not me guv. You must have me mixed up with someone else; use 'em all the
> > time, I do ;-)
> >
> > Anyway, I take on board what you say. Thanks.
> >
> > Charles
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:e7T7UhWSEHA.3728@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > Charles,
> > > > I don't have the Fowler book, but I can feel a purchase or two[/color][/color][/color]
coming[color=blue][color=green]
> > on.[color=darkred]
> > > I
> > > > have the GoF Design Patterns book, which does not mention the[/color][/color]
> Separated[color=green][color=darkred]
> > > > Interface Pattern as such; perhaps under a different name (?).
> > > Fowler's book takes off where the GoF book stops.
> > >
> > > > I have used interfaces in much the way you describe, so I am[/color][/color][/color]
reassured[color=blue][color=green]
> > in[color=darkred]
> > > > that respect.
> > > I may have miss read one of your other posts, I got the impression you[/color][/color]
> did[color=green][color=darkred]
> > > not understand interfaces...
> > >
> > > > With regard to the use of a proxy, it does save copying the data,[/color][/color][/color]
but[color=blue][color=green]
> > with[color=darkred]
> > > > around 50 events being bubbled, each with their own EventArgs class,[/color]
> > that[color=darkred]
> > > > still means another 50 proxy classes.
> > > It really comes down to: How much coupling are you willing to live[/color][/color][/color]
with![color=blue][color=green]
> > ;-)[color=darkred]
> > >
> > > The proxy allows you to avoid coupling, have fair performance, and[/color][/color]
> expose[color=green][color=darkred]
> > > all or most of the same properties in both events. At the expense of
> > > creating the proxy classes...
> > >
> > > > Just to clarify, you say 'assembly', I say 'project'. Are we talking[/color]
> > about[color=darkred]
> > > > the same thing?
> > > Yes
> > >
> > > Hope this helps
> > > Jay
> > >
> > >
> > > "Charles Law" <blank@nowhere.com> wrote in message
> > > news:uCm$ufVSEHA.2780@TK2MSFTNGP09.phx.gbl...
> > > > Hi Jay
> > > >
> > > > I don't have the Fowler book, but I can feel a purchase or two[/color][/color][/color]
coming[color=blue][color=green]
> > on.[color=darkred]
> > > I
> > > > have the GoF Design Patterns book, which does not mention the[/color][/color]
> Separated[color=green][color=darkred]
> > > > Interface Pattern as such; perhaps under a different name (?).
> > > >
> > > > I have used interfaces in much the way you describe, so I am[/color][/color][/color]
reassured[color=blue][color=green]
> > in[color=darkred]
> > > > that respect.
> > > >
> > > > With regard to the use of a proxy, it does save copying the data,[/color][/color][/color]
but[color=blue][color=green]
> > with[color=darkred]
> > > > around 50 events being bubbled, each with their own EventArgs class,[/color]
> > that[color=darkred]
> > > > still means another 50 proxy classes.
> > > >
> > > > Just to clarify, you say 'assembly', I say 'project'. Are we talking[/color]
> > about[color=darkred]
> > > > the same thing?
> > > >
> > > > Charles
> > > >
> > > >
> > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color]
> > message[color=darkred]
> > > > news:u1EuDoQSEHA.620@TK2MSFTNGP10.phx.gbl...
> > > > > Charles,
> > > > > It sounds like you really need to learn the Separated Interface[/color]
> > Pattern[color=darkred]
> > > > > (Martin Fowler's book).
> > > > >
> > > > >
http://www.martinfowler.com/eaaCatal...Interface.html
> > > > >
> > > > > Define an Interface that Class1 uses that Class2 implements. Put[/color][/color]
> this[color=green][color=darkred]
> > > > > interface in the same assembly as Class1 (or a third assembly).[/color][/color][/color]
The[color=blue][color=green][color=darkred]
> > > Class1
> > > > > assembly needs to reference the assembly where the interface is[/color]
> > defined[color=darkred]
> > > if
> > > > > its not in the same assembly. The Class2 assembly needs to[/color][/color][/color]
reference[color=blue][color=green]
> > the[color=darkred]
> > > > > Class1 assembly & the assembly where the interface is defined.[/color][/color]
> Class2[color=green][color=darkred]
> > > can
> > > > > reference Class1 directly, while Class1 can only reference Class2[/color][/color]
> via[color=green][color=darkred]
> > > the
> > > > > interface that it implements.
> > > > >
> > > > > Something like:
> > > > > ' Assembly 1
> > > > > Public Interface IClass2
> > > > > Public Property Value1() As Integer
> > > > > Public Sub Method1()
> > > > > End Interface
> > > > >
> > > > > Public Class Class1
> > > > >
> > > > > Public Sub Test(ByVal object2 As IClass2)
> > > > > If object2.Value1 = 100 Then
> > > > > object2.Method1()
> > > > > End If
> > > > > End Sub
> > > > >
> > > > > End Class
> > > > >
> > > > > ' Assembly 2
> > > > > ' References Assembly 1
> > > > >
> > > > > Public Class Class2
> > > > > Implements IClass2
> > > > >
> > > > > Public Property Value1() As Integer Implements[/color][/color]
> IClass2.Value1[color=green][color=darkred]
> > > > > ...
> > > > >
> > > > > Public Sub Method1() Implements IClass2.Value1
> > > > > ...
> > > > >
> > > > > End Class
> > > > >
> > > > > Note instead of an Interface, you could use an Abstract Base Class
> > > > > (MustInherit).
> > > > >
> > > > > The Interface IClass2 can contain events in addition to[/color][/color][/color]
Properties,[color=blue][color=green][color=darkred]
> > > > > Functions & Subs.
> > > > >
> > > > > Also to elimate the coupling between Presentation & Data, I would[/color][/color]
> use[color=green]
> > a[color=darkred]
> > > > > Proxy object for the EventArgs instead of actually copying the[/color][/color][/color]
data.[color=blue][color=green][color=darkred]
> > > > >
> > > > > Something like:
> > > > >
> > > > > ' From Data layer
> > > > > Public Class DataEventArgs
> > > > > Inherits EventArgs
> > > > >
> > > > > Private Readonly m_amount As Integer
> > > > >
> > > > > Public Sub New(amount As Integer)
> > > > > m_amount = amount
> > > > > End Sub
> > > > >
> > > > > Public Readonly Property Amount As Integer
> > > > > Get
> > > > > Return m_amount
> > > > > End Get
> > > > > End Property
> > > > >
> > > > > End Class
> > > > >
> > > > > ' From Domain Layer
> > > > >
> > > > > Public Class DomainEventArgs
> > > > > Inherits EventArgs
> > > > >
> > > > > Private Readonly m_dataEventArgs As DataEventArgs
> > > > >
> > > > > Public Sub New(dataEventArgs As DataEventArgs)
> > > > > m_dataEventArgs = dataEventArgs
> > > > > End Sub
> > > > >
> > > > > Public Readonly Property Amount As Integer
> > > > > Get
> > > > > Return m_DataEventArgs.Amount
> > > > > End Get
> > > > > End Property
> > > > >
> > > > > End Class
> > > > >
> > > > > Although the Domain layer duplicates all the properties, the data[/color]
> > itself[color=darkred]
> > > > is
> > > > > not duplicate or exposed, as the DomainEventArgs acts as a Proxy[/color][/color][/color]
for[color=blue][color=green]
> > the[color=darkred]
> > > > > DataEventArgs, delegating all the calls to the DataEventArgs...
> > > > >
> > > > > Hope this helps
> > > > > Jay
> > > > >
> > > > > "Charles Law" <blank@nowhere.com> wrote in message
> > > > > news:uDWqYJMSEHA.2704@TK2MSFTNGP10.phx.gbl...
> > > > > > Hi Jay
> > > > > >
> > > > > > > I suspect most of the time the info that the domain layer[/color][/color][/color]
needs[color=blue]
> in[color=green][color=darkred]
> > > its
> > > > > > > events is going to be different then the info needed in the[/color][/color][/color]
data[color=blue][color=green][color=darkred]
> > > > layer's
> > > > > > > events, so each would have its own event handlers...
> > > > > >
> > > > > > I agree that this the case most of the time, it's just that in[/color][/color][/color]
my[color=blue][color=green]
> > case[color=darkred]
> > > > it
> > > > > > isn't. If I used different EventArgs classes I would just be[/color]
> > changing[color=darkred]
> > > > the
> > > > > > object for the sake of it. No information is added or omitted as[/color][/color]
> the[color=green][color=darkred]
> > > > event
> > > > > > passes up the layers.
> > > > > >
> > > > > > As I described in my response to Dan, I have a set of custom[/color]
> > controls[color=darkred]
> > > > that
> > > > > > raise and sink events. These are instantiated by the[/color][/color][/color]
presentation[color=blue][color=green][color=darkred]
> > > layer,
> > > > > but
> > > > > > the command layer is where the corresponding events are sunk[/color]
> > (sinked?)[color=darkred]
> > > > and
> > > > > > raised. I have ended up with tighter coupling than the[/color][/color]
> compiler/IDE[color=green]
> > is[color=darkred]
> > > > > > comfortable with, and I get random, erroneous build errors all[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > time.
> > > > I
> > > > > > have seen others post about this problem, and it comes and goes[/color][/color]
> for[color=green][color=darkred]
> > > me.
> > > > At
> > > > > > the moment it has come, and I can't build my solution because I[/color][/color]
> get[color=green][color=darkred]
> > > > large
> > > > > > numbers of spurious messages about handlers and events having
> > > different
> > > > > > signatures, when they haven't. That's why I am trying to loosen[/color][/color]
> the[color=green][color=darkred]
> > > > > coupling
> > > > > > so that I can just build the thing.
> > > > > >
> > > > > > Charles
> > > > > >
> > > > > >
> > > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > message
> > > > > > news:eVqENGLSEHA.3140@tk2msftngp13.phx.gbl...
> > > > > > > Charles,
> > > > > > > > The presentation layer is coupled to the business layer, and[/color][/color]
> the[color=green][color=darkred]
> > > > > > business
> > > > > > > > layer is coupled to the data layer. So far so good.
> > > > > > > Actually I normally couple the presentation layer to the[/color][/color][/color]
domain[color=blue][color=green][color=darkred]
> > > layer
> > > > > > > (business layer) and couple the data layer to the domain[/color][/color][/color]
layer![color=blue][color=green][color=darkred]
> > > > > > >
> > > > > > > See Martin Fowler's book "Patterns of Enterprise Application
> > > > > Architecture"
> > > > > > > from Addison Wesley
> > > > > > >
http://www.martinfowler.com/books.html#eaa. The sections on[/color][/color]
> Domain[color=green][color=darkred]
> > > > > Model,
> > > > > > > Data Mapper, and Separated Interface discuss how to have the[/color][/color]
> data[color=green][color=darkred]
> > > > layer
> > > > > > > reference the domain layer, instead of having the domain layer
> > > > reference
> > > > > > the
> > > > > > > data layer. Having the data layer reference the domain layer,[/color]
> > allows[color=darkred]
> > > > > > > replacing the data layer very easily! Also I find it provides[/color]
> > better[color=darkred]
> > > > > > > separation (less coupling)...
> > > > > > >
> > > > > > > > Suppose the data layer raises an event, and it passes Me[/color][/color][/color]
(the[color=blue][color=green][color=darkred]
> > > > sender)
> > > > > as
> > > > > > > an
> > > > > > > > object, and e (MyEventArgs, a descendent of EventArgs) to[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > layer
> > > > > > above
> > > > > > > In one of my projects that data layer has custom event[/color][/color][/color]
handlers[color=blue][color=green][color=darkred]
> > > > > > > (MyEventArgs, a descendent of EventArgs), while the domain[/color][/color][/color]
layer[color=blue][color=green][color=darkred]
> > > > simply
> > > > > > uses
> > > > > > > EventHandler & passes EventArgs.Empty. As I found that the[/color][/color]
> domain[color=green][color=darkred]
> > > > layer
> > > > > > > needed to convey less information to the domain layer, then[/color][/color][/color]
the[color=blue][color=green]
> > data[color=darkred]
> > > > > layer
> > > > > > > did to the domain layer.
> > > > > > >
> > > > > > > > We could define a business layer version of MyEventArgs -[/color][/color]
> which[color=green]
> > is[color=darkred]
> > > > > > > actually
> > > > > > > > identical to the one in the data layer - and copy each[/color][/color][/color]
element[color=blue][color=green]
> > to[color=darkred]
> > > > the
> > > > > > new
> > > > > > > > object before passing it on, but that is a lot of typing,[/color][/color][/color]
and[color=blue][color=green]
> > now[color=darkred]
> > > we
> > > > > > have
> > > > > > > > duplication.
> > > > > > > I suspect most of the time the info that the domain layer[/color][/color][/color]
needs[color=blue]
> in[color=green][color=darkred]
> > > its
> > > > > > > events is going to be different then the info needed in the[/color][/color][/color]
data[color=blue][color=green][color=darkred]
> > > > layer's
> > > > > > > events, so each would have its own event handlers...
> > > > > > >
> > > > > > > Hope this helps
> > > > > > > Jay
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > "Charles Law" <blank@nowhere.com> wrote in message
> > > > > > > news:eB2zheKSEHA.3140@tk2msftngp13.phx.gbl...
> > > > > > > > Take a solution with a project hierarchy along the lines of[/color][/color][/color]
an[color=blue][color=green][color=darkred]
> > > > n-tier
> > > > > > > > system, so that we have a data layer, business layer and
> > > > presentation
> > > > > > > layer.
> > > > > > > > The presentation layer is coupled to the business layer, and[/color][/color]
> the[color=green][color=darkred]
> > > > > > business
> > > > > > > > layer is coupled to the data layer. So far so good.
> > > > > > > >
> > > > > > > > Suppose the data layer raises an event, and it passes Me[/color][/color][/color]
(the[color=blue][color=green][color=darkred]
> > > > sender)
> > > > > as
> > > > > > > an
> > > > > > > > object, and e (MyEventArgs, a descendent of EventArgs) to[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > layer
> > > > > > above
> > > > > > > > (the business layer). Suppose also that the business layer[/color][/color]
> needs[color=green][color=darkred]
> > > to
> > > > > pass
> > > > > > > > this event on to the presentation layer. It sends Me as an[/color]
> > object,[color=darkred]
> > > > but
> > > > > > > what
> > > > > > > > does it send e as? It can't send it as MyEventArgs because[/color][/color][/color]
the[color=blue][color=green][color=darkred]
> > > > > > > presentation
> > > > > > > > layer knows nothing of such things. We could couple the
> > > presentation
> > > > > > layer
> > > > > > > > to the data layer, so that it knows what a MyEventArgs is,[/color][/color][/color]
but[color=blue][color=green][color=darkred]
> > > > surely
> > > > > > that
> > > > > > > > is a no-no.
> > > > > > > >
> > > > > > > > We could also remove the definition of MyEventArgs to[/color][/color][/color]
another[color=blue][color=green][color=darkred]
> > > > project
> > > > > to
> > > > > > > > which everything is coupled, but now this common project is[/color][/color][/color]
in[color=blue][color=green][color=darkred]
> > > > danger
> > > > > of
> > > > > > > > being an eclectic mix of stuff that is really specific to
> > > individual
> > > > > > > > projects.
> > > > > > > >
> > > > > > > > We could define a business layer version of MyEventArgs -[/color][/color]
> which[color=green]
> > is[color=darkred]
> > > > > > > actually
> > > > > > > > identical to the one in the data layer - and copy each[/color][/color][/color]
element[color=blue][color=green]
> > to[color=darkred]
> > > > the
> > > > > > new
> > > > > > > > object before passing it on, but that is a lot of typing,[/color][/color][/color]
and[color=blue][color=green]
> > now[color=darkred]
> > > we
> > > > > > have
> > > > > > > > duplication.
> > > > > > > >
> > > > > > > > I am interested to hear what other people do in this[/color][/color]
> situation.[color=green][color=darkred]
> > > > > > > >
> > > > > > > > Charles
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]