Class A
Inherits Csla.BusinessBase
' Contains the standard code - with Protected Constructor
End Class
Class B
Inherits A
' Declares additional Instance Variables
Private Sub New()
End Sub
Public Shared NewB(..........) As B
' The following does not work - generates runtime error
Return CType(A.NewA(...........), B)
End Sub
My class A is a Root object with a lot of children. I thought I could subclass it to offer a simpler "front" to the UI into the object hierarchy. What would be a legal way to do it?
You somehow need to get the type (B) into the data portal. CriteriaBase is designed for scenarios like this.
Have A declare the criteria, but inherit from CriteriaBase. Then the (protected?) factory of A needs to accept a parameter with the type of B. So A's factory might be:
Protected Shared Function GetA(objType As Type) As A
Return DataPortal.Fetch(New Criteria(objType))
End Function
The point is, that the data portal needs to know that it should create an instance of B - that can happen either because the criteria object is nested in B, or through the use of CriteriaBase (which requires that you specify the object type when creating the criteria object).
Thanks Rocky.
Working late? I thought surely everyone is in bed by this time. I will try your suggestions.
Jav
Andres,
Thanks. I am discovering that, and also discovering many other issues. The superclass's DataPortal methods contain code, much of which is tied to its own Type, which ends up being a problem.
I think the solution is to provide B its own DataPortal methods. I can still make the Properties and Methods of A available, as well as provide access to A's Children, to B, but the process of Object creation and acquisition, and the Factory methods, will have to be specific to B. What do you think?
Jav
The preliminary tests show that I can create my subclass by doing the following:
1. Provide the Factory methods that create or fetch, and the DataPortal_Create and DataPortal_Fetch. Criteria class also if needed.
2. Save method of the superclass should work fine. Also, Insert and Update do not need to be duplicated (I think)
3. The PK instance variable of superclass will need to be made Protected so it can be set in the subclass's Create
4. Make the superclass Constructor Protected.
Jav
You may want to read this article about inheritance options
http://www.lhotka.net/Article.aspx?id=e130b265-15cb-453d-9719-d5a944385fd3
Rocky,
I started down this path reading all the discussion about the data and the behavior, and trying to figure out if there is some neat way to rearrange my classes.
Like most other code generators, I am perfecly happy to have a single class totally in-charge of a given DataTable - reading, writing, and validating the data. Why not? But I thought that if I could interpose another "class" between the Root of a hierarchy on the one hand and the UI on the other - a class that is more behavior-oriented and not so much data-oriented - then I could use the same hierarchy in different scenerios by simply interposing a different class.
I have not tested it yet, but I am thinking if it might not be possible for the subclass to have the Factory methods as usual, but to call the base class to populate its data from within the DataPortal methods. At that point the SubClass will already be instantiated and the only question will be of its access to some method of the base class. This is probably not too different from a Collection calling its Child object to load itself.
Jav
Copyright (c) Marimer LLC