Solved

defining a Class

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

Suggested Solutions

Title # Comments Views Activity
Amazon S3 .Net error 5 43
VB/ASP.Net "Value of type 'Date' cannot be converted to 'Integer'" 12 42
C# Service FileSystemwatcher isse 9 46
Selenium and Xpath 4 32
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 aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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