As you might have guessed, I am fairly new to OO design so I’m going to bundle a few questions together:
First off, I've written several .NET libraries over the past few months which basically have the following common classes in a single library (I’ll use Customer as an example):
CustomerCollection (Inherits from System.Collections.CollectionBase)
Customer Exception (Inherits from System.ApplicationException)
CustomerItem (standard class which just represents the fields of a typical Customer)
CustomerReader (reads data from a database and populates its own CustomerCollection full of Customer objects)
CustomerWriter (writes data to a database by iterating through its own CustomerCollection (previously populated by the caller)).
Is there anything particularly wrong with the above design, if so give some practical examples as to why its not so good.
Secondly, I’ve come across a situation where I would like to use an interface as follows:
Interface
IApplicationItem
string Code
string Description
Classes
WindowsServiceItem Implements IApplicationItem
string Code
string ServiceName
string ServerCode
string Description
string ConfigFilePath
QueueForDayItem
int ID
IApplicationItem Application
Etc..
Basically I want to pass an application object into a QueueForDayItem object as above. This works fine as it allows different types of application items to be passed in (i.e. web app, windows app etc.) as long as they implement that interface. However, things get a little more complicated when you want to store and retrieve this data in a database. For example, say I wanted to write the QueueForDayItem to a tblQueueForDayItems database table, how do I store the ApplicationItem information? If I just store the code field how do I later retrieve the description without knowing where this applicationitem came from (i.e. it could be a windows service, web app, win app etc. each of which could be stored in different database tables.) Am I missing something here, or is there a better way of designing this set of interfaces/classes?
Any help would be greatly appreciated.
Thanks
First off, I've written several .NET libraries over the past few months which basically have the following common classes in a single library (I’ll use Customer as an example):
CustomerCollection (Inherits from System.Collections.CollectionBase)
Customer Exception (Inherits from System.ApplicationException)
CustomerItem (standard class which just represents the fields of a typical Customer)
CustomerReader (reads data from a database and populates its own CustomerCollection full of Customer objects)
CustomerWriter (writes data to a database by iterating through its own CustomerCollection (previously populated by the caller)).
Is there anything particularly wrong with the above design, if so give some practical examples as to why its not so good.
Secondly, I’ve come across a situation where I would like to use an interface as follows:
Interface
IApplicationItem
string Code
string Description
Classes
WindowsServiceItem Implements IApplicationItem
string Code
string ServiceName
string ServerCode
string Description
string ConfigFilePath
QueueForDayItem
int ID
IApplicationItem Application
Etc..
Basically I want to pass an application object into a QueueForDayItem object as above. This works fine as it allows different types of application items to be passed in (i.e. web app, windows app etc.) as long as they implement that interface. However, things get a little more complicated when you want to store and retrieve this data in a database. For example, say I wanted to write the QueueForDayItem to a tblQueueForDayItems database table, how do I store the ApplicationItem information? If I just store the code field how do I later retrieve the description without knowing where this applicationitem came from (i.e. it could be a windows service, web app, win app etc. each of which could be stored in different database tables.) Am I missing something here, or is there a better way of designing this set of interfaces/classes?
Any help would be greatly appreciated.
Thanks