Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

defining a Class

Posted on 2014-09-09
4
278 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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