Help /w implementing Interfaces

Help /w implementing Interfaces

Old forum URL: forums.lhotka.net/forums/t/6816.aspx


Jack posted on Friday, April 17, 2009

I seem to have gotten myself into a bit of a bind and was looking for some confirmation that the approach I'm taking makes sense - it has to do with implementing PRISM and CSLA.

Anyhow I have created a standard interface for a view / presenter.  In my view I have some standard events that I need/want.  My interface for the view is passed to the constructor of my presenter and I can subscribe to the events I want.  I have a set of standard events that I need to manage for all the different views in a single master view /w a controller.

Everything works great and I can delegate the events as needed up the chain.

My problem is that a couple of my views need some additional events and properties.  So I started to create another layer of view/presenter and ran into a few issues.

so I started with IView1 & IPresenter1

IPresenter1 has a property
IView1 View {get;set}

and then I create my Presenter Object:
public SomePresenter(IView1 view)
{
    View = view;
    View.Event1 += ...
    View.Event2 += ...
}

Now I have a more complicated view that I need an additional event so I created another set

IView2 : IView1
    event EvemttHandler <...> Event3

I also created a new presenter IPresenter2 : IPresenter1

I started to put in
new IView2 View {get;set}

so as to 'hide' the prior implemenation ... that didn't work.  When I actually create my real view from IView2 I have to implement both View Properties which I can't do.

I then decided that in my Presenter2 I would just cast my IView to an IView2 and subscribe to the events.  This seems to work and seems okay in my mind but is it asking for trouble down the road?  Sort of seems a bit like I almost tried to merge inheritance /w two interfaces.

public Presenter2(IView2 view)
{
    View = view;

    View.Event1 += ...
    View.Event2 += ...
    (View as IView2).Event3 +=
}

Thanks

jack

rfcdejong replied on Friday, April 17, 2009

Your last peace of code is a bit strange, as u get a view of IView2 passed into the constructor, but then u still have to cast it.

Anyway, in my opinion u should always have only 1 view with his presenter. Never try to do cross binding them somehow. Show a view in a region and it constructs always the same presenter. Don't use the presenter for 2 differend views.

I also think that u should post this at the codeplex forum for Composite Application Guidance, that team has more knowledge about the Model-View-Presenter pattern.

Jack replied on Friday, April 17, 2009

The reason I was casting it was because I had made the assignment to the
local View property first which is of type IView1.

I am only having one view associated with one presenter. It's just that I
started with a common view/presenter interface and I'm trying 'enhance' this
particular one. I'm doing that because I have 5 views displayed at once
that share many common features. I'm using a controller to manage the
interaction between them all.

This particular view happens to have a list on it so I need to handle the
change in list items where the other views don't have that.

Really my question boils down to the best way to 'extend' an interface that
is used in more than one place. The other option would be to add a generic
'listItemChanged' event to my IView1 interface and not use it anywhere else.
That seemed a little annoying since I had to implement it in each object but
I'm not that opposed to it.


I will try posting over there as well but to me this was more an interface
question than a CAL question and I really respect the knowledge here and
CSLA is full of interface implementations.

Thanks

jack

-----Original Message-----
From: rfcdejong [mailto:cslanet@lhotka.net]
Sent: April-17-09 2:09 PM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] Help /w implementing Interfaces

Your last peace of code is a bit strange, as u get a view of IView2 passed
into the constructor, but then u still have to cast it.

Anyway, in my opinion u should always have only 1 view with his presenter.
Never try to do cross binding them somehow. Show a view in a region and it
constructs always the same presenter. Don't use the presenter for 2
differend views.

I also think that u should post this at the codeplex forum for Composite
Application Guidance, that team has more knowledge about the
Model-View-Presenter pattern.

rfcdejong replied on Sunday, April 19, 2009

Sorry for not responding anymore, i was hoping someone else did, since i don't see the problem or i'm not understanding your real problem. U could explisitly impliment the interface to hide it from the outer world. It isn't really an CSLA nor CAG problem ;)

Did u get any help on another forum?

ozitraveller replied on Sunday, April 19, 2009

I think I'm following the problem. So hopefully this will help. :)

public class SomePresenter : IView1
{
}

public class Presenter2: IView1, IView2
{
}


rfcdejong replied on Tuesday, April 21, 2009

That isn't according CAG rules ;)
It's more about using generics

public class Presenter1
{
public Presenter1(IView1 view)
{
}
}

However it's possible to create a PresenterBase and a internal interface and impliment that interface explicit

public PresenterBase where T is IViewBase
... do generic stuff

Copyright (c) Marimer LLC