I have an application that follows the basic methodoligy in the CSLA framework. Specificly, the objects know how to maintain their state and how to create, update, delete themselves. The car class shows this idea.
public class Car
{
public int Color {get;set;}
public void Drive(){.. Do something Here}
private Car(){} // Only factory method can create this object
public static Car New()
{
Car car = new Car();
car.DataFetch();
return car;
}
private void DataFetch()
{
// Fill up this object with values from DB or where ever
this.Color = repo.valueForColor();
// ...
}
}
The application creates and destroys over 1 Million objects and the shear number of object creation is impacting performance due to the amount of garbage collection going on. Also a lot of these objects are completely transitory and are used to simply pass data onto the repository.
I've read about the flyweight pattern which seems like it may suit my needs. And I've also read about Object Pooling and the associated code.
What I'm having trouble with is creating a million Car objects using a pool or externalizing the data for a flyweight in conjunction with the principle of the Object should maintain it's own data and data access.
Any ideas on how to accomplish this?