Csla doesn't support polimorfism via interfaces?

Csla doesn't support polimorfism via interfaces?

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


jureleskovec posted on Wednesday, March 18, 2009

The only way the csla supports polymorphism is via 'BusinessBase'. I tried to use interface type as a property type and I noticed the 'Parent' property of a child property returns null. This is not a crucial deficiency but I think this is a just a minor bug that can be fixed, or...?

I can post the test case code for clearance if requested.

-- Jure

JoeFallon1 replied on Wednesday, March 18, 2009

I am confused by your claim. For years the statement has been the other way around!

In other words - Generic base classes are NOT polymorphic. So cast to a common interface to obtain polymorphic behavior.

Please explain what you really meant.

Joe

 

jureleskovec replied on Wednesday, March 18, 2009

Sorry for not being clear enough. I didn't say you can't cast BOs to any interface they implement and is actually not a big deal (In this case just use non-generic BusinessBase as a managed property type).

What I try to say is that you can't create managed csla properties of interface types (like 'IChild'). If you do so, everything looks good except the 'Parent' property of the referenced child object won't be set (there might be other issues also I haven't noticed).

To reproduce the issue:
- Create interface 'IChild'
- Create BO class 'Child' which implements 'IChild'
- Create BO class 'Root'. It has a managed property of type 'IChild' (NOT the 'Child') but references an instance of 'Child'.
- When you create the 'Root' instance check the 'root.Child.Parent' and you will notice its 'NULL'!

************************* Code **************************

public class Root : BusinessBase<Root>
    {
        private static PropertyInfo<IChild> ChildProperty = RegisterProperty(new PropertyInfo<IChild>("Child"));
        public IChild Child
        {
            get { return GetProperty(ChildProperty); }
            set { SetProperty(ChildProperty, value); }
        }


        protected override void DataPortal_Create()
        {
            using (BypassPropertyChecks)
            {
                Child = DataPortal.CreateChild<Child>();
            }
        }
    }


    public interface IChild
    {
    }


    public class Child : BusinessBase<Child>, IChild
    {
    }

********************************************************

After the BOs definition run the folowing:
Root r = DataPortal.Create<Root>();
and check the 'r.Child.Parent' through the debugger (Parent property is declared as protected).


-- Jure

RockfordLhotka replied on Wednesday, March 18, 2009

IChild simply needs to inherit from Csla.Core.IEditableBusinessObject (if I remember correctly).

jureleskovec replied on Thursday, March 19, 2009

True.

-- Jure

Copyright (c) Marimer LLC