product1 = Products.GetProductByID(1);
product2 = Products.GetProductByID(2);
WriteOutout(product1.Name);
WriteOutout(product2.Name);
WriteOutout(product1.Description);
WriteOutout(product2.Description);
So I assume here that Products is a service that sets the index and returns the IBO object. Unless I'm mistaken all 4 of these outputs would return the name and description for product2.
I think this is a real-world example: say I have a collection of 10 products, and I want to compare only 2 of them... There are ways to code around this, once you know it will happen, but my biggest concern is that having Products.GetProductByID(1) return the IBO, which is just a shell that defines a record, until it has an index, is misleading, as we would naturally assume it to always return the data for product1 when in fact it just returns the data for the current product.
Something like this is less natural, but I'm considering whether it isn't more "self-evident" what is going to happen:
product1 = products.getProductIndexByID(1);
product2 = products.getProductIndexByID(2);
WriteOutput(Products.GetProductProperty(product1, "name"));
WriteOutput(Products.GetProductProperty(product2, "name"));
WriteOutput(Products.GetProductProperty(product1, "description"));
WriteOutput(Products.GetProductProperty(product2, "description"));
Obviously, this is just an example that could be further abstracted to handle any collection, not just Products.
There is a second reason that I like this, as clunky as it seems. I can "late-bind" properties that I might or might not need, to avoid storing too much data up-front; so, when GetProductProperty saw that "description" was not yet populated, it could look at a map that tells it how to get description.
I'm toying the notion of the following Objects:
- ProductMap - tells me which properties will be available in this IBO, and which methods are responsible for getting those properties.
- Collection - the "transformed" data, stored as a query or structure...
- Iterator - provides the ability to move/loop through a collection
- Service - methods to locate the index of a record, as well as methods to populate and retrieve properties on the record. It transforms the data as it gets it, using instruction from the ProductMap.
No comments:
Post a Comment