I'm trying to create a Data Access Layer using TCP/IP to receive regular updates from a (non-windows) computer. This data is for display (and control) of process data (steel furnace). We customize this data for each customer, and I want to separate the core data set we need for every installation from the project-specific data each customer wants displayed that's unique to their way of doing business. Oh, and some applications control multiple furnaces, which is why I have an array.
I have a base, abstract (MustInherit) class with abstract (MustOverride) methods that are called by the parsing and debugging routines. My base class assumes that all of the core data will be first in the message, and it parses that, then calls the MustOverride parsing method of the project-specific class to finish parsing the data.
Here's where I need help. I need to "get" the FurnaceData object when the message comes in, and if it doesn't exist, I need to create one (and only one). I can't figure out how to get around this without breaking the whole thing.
I can declare the constructor of my abstract base class as protected (or private) to prevent instantiation outside of my base class (object factory, if you will), but an abstract class can't instantiate its own objects because they're abstract. I can't instantiate a concrete (child) object, because I don't know what they are yet. And even if I did, that would mean my parent contained intimate information about a specific child implementation -- a recipe for disaster.
I hate to do this, but I'm thinking the only way I can accomplish this is by asking the creator of the child to implement an array of singletons. I wouldn't mind if there were some way I could think to make it contractual (abstract), but I just can't envision it.
I'm going to see if I can implement this in the child class, in the hopes that the implementation will give me some further insight, but if anyone else has some inspiring thoughts, I'd love to hear them.
-rod
I have a base, abstract (MustInherit) class with abstract (MustOverride) methods that are called by the parsing and debugging routines. My base class assumes that all of the core data will be first in the message, and it parses that, then calls the MustOverride parsing method of the project-specific class to finish parsing the data.
Here's where I need help. I need to "get" the FurnaceData object when the message comes in, and if it doesn't exist, I need to create one (and only one). I can't figure out how to get around this without breaking the whole thing.
I can declare the constructor of my abstract base class as protected (or private) to prevent instantiation outside of my base class (object factory, if you will), but an abstract class can't instantiate its own objects because they're abstract. I can't instantiate a concrete (child) object, because I don't know what they are yet. And even if I did, that would mean my parent contained intimate information about a specific child implementation -- a recipe for disaster.
I hate to do this, but I'm thinking the only way I can accomplish this is by asking the creator of the child to implement an array of singletons. I wouldn't mind if there were some way I could think to make it contractual (abstract), but I just can't envision it.
I'm going to see if I can implement this in the child class, in the hopes that the implementation will give me some further insight, but if anyone else has some inspiring thoughts, I'd love to hear them.
-rod