Defining a Class

Posted on 2014-08-25
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

    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 29

    Assisted Solution

    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
    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

    Thanks for all comments

    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

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now