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.
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?
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
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
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
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
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