Solved

defining a Class

Posted on 2014-09-09
4
272 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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now