Solved

defining a Class

Posted on 2014-09-09
4
280 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
[X]
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
  • 2
  • 2
4 Comments
 
LVL 36

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 36

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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