[Last Call] Learn how to a build a cloud-first strategyRegister Now


Defining a Class

Posted on 2014-08-25
Medium Priority
Last Modified: 2014-08-26
I am relatively new to c#. I understand what a Class is but I am unsure about how small/large a class definition should be. For example I have an application in mind which I am about to start working on. This application will take a series of rules which have been defined within a ms database and given a transaction name and it will execute these rules in a predefined sequence defined within the database. Database rules can be input rules, output rules, logic rules, constant rules, menu rules etc.. and each database rule can consist of 40-50 field definition. When a particular transaction is selected then the sequence of rules for that transaction will be load up into arrays or containers and the transaction will execute from these arrays. The transaction will have if/then/else logic , error checking, database input/output.

My Questions is:
 do I define just 1 class called "transaction"        and get this the class members to perform the database I/O , array/container processing, error checking etc. etc.. or should I break this down into much smaller classes ? Appreciate if someone could point me towards some reading material which would help me understand what should be contained within a class ?

Question by:pclarke7

Accepted Solution

Joshua Lucier earned 501 total points
ID: 40283991
That database doesn't sound like it's normalized very well if it has 40-50 fields per record.  There's two ways of doing this.  You can have a class called query accept a query, or you can create a 'model' of classes to match your database architecture.  From these you can extract the query.  There are often model architecture libraries out there that will do this for you.  I'm not an expert with c#.  If you want to create your own model, I would use one class per table ('object').  If this is a nosql database, there will be a much different approach.
LVL 30

Assisted Solution

anarki_jimbel earned 501 total points
ID: 40284169
First, regarding "not normalized DB".  We have tables with up to hundred fields, and just believe me - it is well normalised. Depends on a scale and complexity of an application. Anyway, it's irrelevant to the question.

it is not easy to tell what class structure you need, Definitely, you need more than one class. First, I'd have classes that are responsible for connecting to DB, retrieving results, etc. Other classes would be "model" classes as was suggested above, to keep data.
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 498 total points
ID: 40284572
Your question is very broad but I would suggest to find what element are common to all rules, there you will define your parent class. That may reduce the property count at the child classes, which seems to be too much.

Regarding the operations mentioned (database I/O, array processing, error checking), you can implement some helper classes if those operations are complex, by passing a reference to the 'parent' class.

Author Closing Comment

ID: 40286304
Thanks for all comments

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

831 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