NOODB: Abstract Classes

This is very similar to the INTERFACE update.

The CAR object has a property called DRIVER, which is of type DRIVER, which is an abstract class.

GIRAFFE inherits from DRIVER

BABY GIRAFFE inherits from GIRAFFE.

CHRYSLER300 inherits from CAR.

So, the type of DRIVER is a base class. We assign to it an instance of BABYGIRAFFE which is, ultimately, a driver.

                NoodbClient client = new NoodbClient(new Server(TestUtility.DefaultUnityContainer));
                client.RegisterType<Chrysler300>();
                client.RegisterType<BabyGiraffe>();

                Car car = new Chrysler300
                {
                    Driver = new BabyGiraffe { NeckLength = 40, Id=Guid.NewGuid() },
                    Id = Guid.NewGuid()
                };

                client.Save(car);

                Car fromDb = client.GetObjects<Car>()[0];
                Assert.IsInstanceOfType(fromDb.Driver, typeof(BabyGiraffe));

This went in pretty easy. The PropertyResolver had a problem with BabyGiraffe because, as it worked up the graph, it found the same properties multiple times. So, it would try to add the same property to the dictionary multiple times. The knee-jerk reaction was to add a CONTAINS check before the add, but I didn’t want to do that until tracing the whole thing and confirming the problem.

                    // C : B : A
                    // When c and b are parsed, they will both try to add the properties from A.
                    // So it will encounter the same properties multiple times.
                    if (!objectProperties.Contains(p.ObjectTypePropertyId))
                    {
                        objectProperties.Add(p);
                    }

I have a couple more scenarios to test, but I expect them to work. (IE: the property type is somewhere in the middle of a class hierarchy)

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: