Generics classes and object creation
-
At the moment I have the following classes : Record ( which is the superclass ) - MessageHeaderRecord ( the superclass for the next classes ) : - InfosRecord ( the class for the I tag representing the informations from text ) - CommentRecord - OrderRecord - ResultsRecord - TerminatorRecord For each of this classes I have a corresponding class (MessageHeaderRecordFields ,...) in which I created the fields to put the infos from the file. So far so good ... MessageHeaderRecord beeing the superclass for the rest of classes I put inside of it a generic List : private List m_Infos = new List() internal List Infos { get { return m_Infos; } } and the constructor is internal MessageHeaderRecord() { RecordType = RecordType.MessageHeaderRecord; m_Fields = new MessageHeaderRecordFields(); // } I did this because I want to access the objects as follows : Message MyMessage = new Message(); MyMessage.Infos[3].Fields.SequenceNumber = "1"; MyMessage.Infos[3].Fields.InfoName.LastName = "John"; // Create a new info int nInfoIndex = MyMessage.AddNewInformation(); (*1) // Set the info specific data such as name, age, etc. for the info we just addded MyMessage.Infos[nInfoIndex].Fields.InfoName.LastName = "John"; // Add an order record for this patient int nOrderIndex = MyMessage.Infos[nInfoIndex].AddNewOrder(); (*2) // Set the order specific information for the new order MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].Fields.OrderID = "11"; // Add a comment to this order MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewComment(); (*3) // Set the text for the new comment MyMessage.Infos[nInfoIndex].Orders [nOrderIndex].Commment.Fields.CommentText = "I am a comment."; // Add a Result to this order nResultIndex = MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewResult(); // Set the new result's data MyMessage.Infos[nPatientIndex].Orders[nOrderIndex].Results[nResultIndex].Fields.SequenceNumber = "333"; (*4) So my problems redefined would be (*1) - In which class to put the AddNewInformation() method (*2) - In which class to put the Orders List and where to put the AddNewOrder() method (*3) - In which class to put the Comment List and where to put the AddNewComment() method (*4) - Same with Results List and AddNewResults() method Please help me with this issues because I really cant figure them out. Thank you in advance
-
At the moment I have the following classes : Record ( which is the superclass ) - MessageHeaderRecord ( the superclass for the next classes ) : - InfosRecord ( the class for the I tag representing the informations from text ) - CommentRecord - OrderRecord - ResultsRecord - TerminatorRecord For each of this classes I have a corresponding class (MessageHeaderRecordFields ,...) in which I created the fields to put the infos from the file. So far so good ... MessageHeaderRecord beeing the superclass for the rest of classes I put inside of it a generic List : private List m_Infos = new List() internal List Infos { get { return m_Infos; } } and the constructor is internal MessageHeaderRecord() { RecordType = RecordType.MessageHeaderRecord; m_Fields = new MessageHeaderRecordFields(); // } I did this because I want to access the objects as follows : Message MyMessage = new Message(); MyMessage.Infos[3].Fields.SequenceNumber = "1"; MyMessage.Infos[3].Fields.InfoName.LastName = "John"; // Create a new info int nInfoIndex = MyMessage.AddNewInformation(); (*1) // Set the info specific data such as name, age, etc. for the info we just addded MyMessage.Infos[nInfoIndex].Fields.InfoName.LastName = "John"; // Add an order record for this patient int nOrderIndex = MyMessage.Infos[nInfoIndex].AddNewOrder(); (*2) // Set the order specific information for the new order MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].Fields.OrderID = "11"; // Add a comment to this order MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewComment(); (*3) // Set the text for the new comment MyMessage.Infos[nInfoIndex].Orders [nOrderIndex].Commment.Fields.CommentText = "I am a comment."; // Add a Result to this order nResultIndex = MyMessage.Infos[nInfoIndex].Orders[nOrderIndex].AddNewResult(); // Set the new result's data MyMessage.Infos[nPatientIndex].Orders[nOrderIndex].Results[nResultIndex].Fields.SequenceNumber = "333"; (*4) So my problems redefined would be (*1) - In which class to put the AddNewInformation() method (*2) - In which class to put the Orders List and where to put the AddNewOrder() method (*3) - In which class to put the Comment List and where to put the AddNewComment() method (*4) - Same with Results List and AddNewResults() method Please help me with this issues because I really cant figure them out. Thank you in advance
Maybe I'm getting this wrong, but from what I understood, all the Add* methods are a bit reduntant if you don't do any special initialization inside them. For example in *1:
// Create a new info int nInfoIndex = MyMessage.AddNewInformation(); (*1) // Set the info specific data such as name, age, etc. for the info we just addded MyMessage.Infos[nInfoIndex].Fields.InfoName.LastName = "John";
Could just be done like:Info information = new Info (firstName, lastName, ...); MyMessage.Infos.Add (Info);
While this doesn't retrieve the index so you can change afterwards, you can setup the class beforehand and then add it. This can be used for all the other questions as far I understand. If this wasn't what you were asking, then my apoligies.Bruno Sousa Software Consultant http://www.luasys.com