Solved

defining a Class

Posted on 2014-09-09
4
277 Views
Last Modified: 2014-09-11
Hello,
in my c# application I have multiple transactions which are made up of multiple records with each record having a set number of fields

example

Trans Trans Trans    
Name Seq     Type     Description      Instruction  etc..    
Tran1  001        T         start      
Tran1  002        I          xxxxxxxxx        yyyyyyyyy    
Tran1  003        L         xxxxxxxxx        yyyyyyyyy    
..
Tran1  100        T         End
 
I want to define a class called "transaction" and to be able to read the entire collection of records in the transaction into this class rather than just have 1 record of the transaction in the class.  The transactions also have a transaction header record which holds defaults for the transaction which I would like to have included in the class.  I'm thinking that the best way to do this is by using collections. 1 collection for the transaction detail records, another for the transaction header. Is this a suitable approach to creating a class for my transactions. Any advice welcome.

regards
Pat
0
Comment
Question by:pclarke7
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 40313619
Please consider creating a Transaction class that contains a list  of Sequence instances as follows:
public class Sequence
{
  public char Type {get; set;}
  public string Description {get; set;}
  public string Instruction {get; set;}
  //Other props/methods 
}

public class Transaction
{
  public string Headers {get; set;}
  public string Name {get; set;}
  public List<Sequence> Sequences {get; set;}
  //Other props/methods 
}

Open in new window

Note: You may consider create enumerators for Type or any special subclass for well know types like start/end.
0
 

Author Comment

by:pclarke7
ID: 40315733
Thanks Miguel,
Thanks for your comments, I have a couple of questions:

1. what is the benefit of using a List over Container.  I was under the impression that container had move functionality than list.

2. Excuse my ignorance here (I'm new to c#). If I create a class called Sequence, which holds all of the "Fields" in my transaction, does this means that if I have 100 lines in a transaction then I would need 100 instances of class Sequence with each instance being a new element of List ?  Does Sequence need to be a class or can it be a struct ?

If you can point me to any reading material related to this I'd appreciate it .

What I am trying to achieve is the following:
I could have hundreds of different transactions , some being menus whilst other are applications running sql statements. Each transaction will have a unique name and can have an unlimited number of transaction lines which will be executed by sequence number. When a user selects a transaction I want to read the full transaction set for the database into a transaction class, just once , along with the transaction header, associated error messages etc... After the class is created then movement within the transaction will be done from within the class rather then any further database I/O.


regards
Pat
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40315922
1. A generic list is more functional than a container. It provides better find methods and type safety. Also your sequence class does not need to implement IComponent

2. For your case, you should use a class to be in line with M$ guidelines
Notes: a) If you are new to C#, use class first and you can later on use struct if you have  memory issues.
b) A nice discussion of these guidelines, including how M$ violates them is shown here.

My suggestion will be to build a prototype based on my above post and evaluate whether memory is a concern or if you require to tackle other performance issues. I usually do not optimize at this stage as it may not be needed.
There are other ways to improve performance but it goes beyond the scope of this question. (It requires more knowledge about your business logic/process - you may be better off hiring a consultant to help you with the high level design details)
0
 

Author Closing Comment

by:pclarke7
ID: 40317992
Thanks Miguel,
much appreciated. I will go with generic list and see where this takes me.

regards
Pat
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question