views:

240

answers:

2

Hello,

I would like to use Model View Presenter pattern for a library containing user controls which will be used in other projects.

According to MVP I have to implement an IView-interface on a user control and pass it on to a Presenter-class.

In my case the consumers don't need access to the IView-contract. But because the IView-interface is a public contract it means that consumers of the user control can also access its methods\properties and I want these to be only accessible for the Presenter.

What is a good way to accomplish this?

A: 

I always consider User Controls tied to the Views not be a separate view themselves. They should be able to access any Presenter that the view they are tied can access but are not in themselves views. Rather they are part of a view and can be replace or altered without concern to the present if the UI changes.

In your specific example I would have the User control not implement any view interface. Instead I would just have the User Control Assembly reference the Presenter Assembly and have properties to allow access to the View Object that it is a part of.

RS Conley
+1  A: 

I've found a solution for my situation.

I make my IView-interfaces internal and implement them explicitly on the user controls. This way the IView-interfaces is not part of the public interface of a user control which is what I need in my case.

anagels