Interface UI & BO problem

Interface UI & BO problem

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


MSerrate posted on Thursday, January 18, 2007

Hello,

 

I’m working in a windows main form (simple at the moment, a grid and two buttons) from which I will inherit all the other forms using my own class subclassing BusinessListBase.

 

In this base main form I want to obtain the collection and save it too.

I’ve tried a generic form but there’s the problem with the designer. I can also use reflection but it’s a very ugly solution.

 

Searching at forums I found the idea of using the CSLA interfaces but I’m a little lost about it.

 

For example, if I use that:

 

private Csla.Core.IEditableCollection m_editableCollection;

 

How I obtain the items in the form of:

m_editableCollection = m_editableCollection.GetAll();

 

 

And about Save, how I can do: m_editableCollection.Save();

As you can see I need some light in my dark journey

 

 

Thanks in advance guys.

MSerrate replied on Thursday, January 18, 2007

I think that I’ve solved the save problem with interface inheritance, but with the method GetAll() I haven’t the same luck as it is static.

 

How can I manage this? Must I use reflection?

dshafer replied on Thursday, January 18, 2007

You should be able to create your own interface that inherits from IEditableCollection and has your custom Save() and GetAll() methods on it.  Then in your Editable Collection classes you can inherit from your custom interface and implement the Save() and GetAll() methods.  One problem I see with this approach is that most likely your GetAll() method would need to have different parameters based on which of your Editable Collections you are using.  This will not be a problem if none of the fetch methods in your Editable Collection classes have parameters, but this is highly unlikely.  The only other option i could think of would be to pass an array or collection of parameters to the GetAll() method, but that could get kinda messy.

Dustin

MSerrate replied on Thursday, January 18, 2007

The problem is in the GetAll() method because is a static-shared method and interfaces doesn’t allow these methods.

Although I don’t like it, I think that the solution is the use of reflection

RockfordLhotka replied on Thursday, January 18, 2007

In version 2.1 there's the ISavable interface, specifically added to support the idea of a UI framework that can save any business object (editable root, collection or not).

MSerrate replied on Friday, January 19, 2007

Thank you both for your inputs. As I mentioned the “save” problem is solved but not the other one yet.

 

My base class “ExampleBusinessListBase” (subclassing Csla.BusinessListBase) have a static GetAll() method, and others like CanAddObject() and so on (also static).

I want to use these methods in my base UI form “ExampleBusinessListWindow”… but I cannot use an interface like the “save” method because are static methods!!!

 

Is there any good solution to manage that???

 

Thanks in advance

SonOfPirate replied on Friday, January 19, 2007

Remember that in OOP terms, "interface" is not strictly an entity declared as an interface (Interface in VB) - an abstract base class also falls into this realm.

As such, my suggestion is (and the way I've handled this) is to create your own base (abstract) collection class that exposes the static GetAll method.  Then, use this class for your form's variable rather than the IEditableCollection interface.

To implement GetAll, use your criteria object to define the action in your DataPortal_Fetch method which is overriden in the actual class.  This will allow you to handle the variations that may be necessary as mentioned previously.

HTH

 

ajj3085 replied on Friday, January 19, 2007

Your best bet is probably to create a static factory which returns only the subclass collection.

You may also want a security checker class.. but I have to say that it seems unlikely that the subclasses would all have the same specific access methods.  If they do, perhaps the static factory can have those CanAddObject methods.

RockfordLhotka replied on Friday, January 19, 2007

Also remember that there are different ways to implement the factory pattern.

I chose, in the book and most of my work, to use static methods as factories.

However, it is equally valid to create a separate factory class, where you instantiate the factory in order to invoke the factory method:

CustomerFactory fact = new CustomerFactory();
CustomerList customers = fact.GetAll();

Because the factory is now an instantiated object, you can create a factory interface or factory base class to get commonality across all your factories.

Copyright (c) Marimer LLC