Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Generics classes and object creation

Generics classes and object creation

Scheduled Pinned Locked Moved C#
jsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndyHug
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • A AndyHug

      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

      B Offline
      B Offline
      Bruno M T Sousa
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups