2

I have a Data class that can be placed inside a DataCollection class that can be placed inside a DataCollectionCollection class. Kinda like an egg can placed inside a box that can be placed inside a crate.

The Data class can be "standardized" through a special process. Standardizing it will create a new StandardizedData class that contains some information about the standardization process it went through.

The StandardizedDataClass can be placed only inside a StandardizedDataCollection. The StandardizedDataCollection class must only accept StandardizedData objects that have gone through a similar standardization process.

A StandardizedDataCollection class can only be placed inside a StandardizatedDataCollectioCollection class which again, must only accept StandardizedDataCollection classes that have gone through a similar standardization process.

There are a few ways I've thought of on how to do this:

  • Have StandardizedData, Collection, and CollectionCollection store than the standardization info. I'd like to avoid this scenario if possible as there could be a 1000 StandardizedData object which will be loaded into the small memory of mobile devices.

That's the only idea I can explain on paper for now. One last thing: StandardizedData should not be allowed to be standardized again as this will make it less accurate.

2
  • 1
    What kind of operations do the Collection adn CollectionCollection classes have, roughly? – Ben Aaronson Apr 30 '16 at 10:05
  • I've worked with quite a few people who have a knack for making the simple complex. I eventually learned to ask what they are really trying to achieve at a Use-Case level versus what is their "complex" design trying to achieve. It always leads to far simpler solutions. It sure seems like that would be exactly what I'd be asking you if we worked together. – Dunk Aug 29 '16 at 21:38
1

Because of the current design, I bet you have to have all these objects instantiated so you can have the cross references, for example, from a Data object to its StandardizedData object; ditto for collections and collection-collections.

Get rid of more than half the classes and make a simple hierarchy.


Why have 2 classes for data? Seems to me that un-standardized data is just a special case of standardized. And you say that the StandardizedData contains some information about the standardization process it went through. That just sounds like "metadata". So why not have Data contain its own information?

public class Data {
    public StandardizedInfo MyStandardizingInfo { get; protected set; }
}

I assume that a null StandardizedInfo reference means that data is not yet standardized. This would not be possible if Data did not contain the reference.


There is no StandardizedDataCollection, just:

public class DataCollection {
  protected List<Data> myData {get; set;}
}

The standardized data part of the collection.


And I see no reason for a "CollectionCollection". This could go on forever. So just have:

public class DataCollection {
  public DataCollection innerCollection {get; protected set;}
}

You do not need a special type - xxxCollectionCollection - to enforce a 1-deep hierarchy. Just build it that way.


Now everything can be lazily instantiated. You could start with an empty DataCollection and add to it when necessary. Likewise you can have a Data object and instantiate its StandardizedData object only when needed.


If you really must express "standardized data collection" yet save memory then write an enumerator on the DataCollectionclass that yields the StandardizedData objects.

1
  • Didn't expect to get such a nice answer so long after I asked the question. – user176583 Aug 29 '16 at 12:55
1

Given

Have StandardizedData, Collection, and CollectionCollection store than the standardization info. I'd like to avoid this scenario if possible as there could be a 1000 StandardizedData object which will be loaded into the small memory of mobile devices.

you could investigate the flyweight pattern. If your standardisation info is replicated, then you could just store a reference to one instance of this throughout your entire collection (or collection of collections). If your standardisation info differs slightly between collections you could partition it should that you don't replicate the parts you don't need.

If this doesn't apply, have you considered using your 'collection' classes to lazily load (and throw away) data as you require it ? So that when you give me a 'DataCollection' object, it won't contain a sequence of data until I actually need it, and only load it then (presumably disposing of other data that I don't need). That too would reduce your memory footprint, at the expense of taking longer to run, and requiring a connection to a remote data source.

-1

It seems you have just one data class with a list of contained data objects as a property like radarbob suggests. Standardization could be a process performed any time a data object chamges, assuming the standardized state is the only ultimately interesting state. It is not clear whether "standardisation data" is a set that applies to all or specific to an object. In the first case it can be a static member, in the latter a non-static member of the data class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy