Visual C Express - Separate Data From Display - 3rd In A Series
The solution, called called "InterestCalculatorSolution", contains a Windows Application Project called "InterestCalculator", and a Class Library Project called "FinancialLib". This solution is a simple example of how data is separated from presentation in modern visual programming.
Form Classes and Data Classes
The heavy lifting in the InterestCalculator program is done by two classes:
CompoundGrowth handles presentation in the InterestCalculator. It is a C# class based on the .net Framework "form" class. In object oriented terms, CompoundGrowth is said to "inherit" the .net Framework "form" class. A "form" class is basically a blank form. The CompoundGrowth class is based on a blank form but adds a a button and some text input boxes so a user can input financial information, and an output text box so the program can display the results of interest growth calculations. CompoundGrowth contained in the "InterestCalculator" project.
cFinancial handles calculations. It uses principal, interest rate, time, and compounding schedule to calculate the growth of an investment. cFinancial is a C# class, but it is not based on any other C# class. cFinancial is contained in the "FinancialLib" project.
Who's In Charge?
Every C# solution needs a "Startup Project". In the InterestCalculatorSolution, the InterestCalculator project is the startup project. Initially the program loads loads the CompoundGrowth form and presents it to the user, but the cFinancial class is not be called until the user actually presses the "Calculate Amount" in the CompoundGrowth form.
In other words, the cFinancial class is a slave to the CompoundGrowth class. In fact, the cFinancial class is only used in one routine, btnCalculateAmount_Click, which is called when the " Calculate Amount" button is pressed.
The code to use the cFinancial is quite simple, I have reproduced it below, with the comments changed slightly for this article:
// Create a financial object from the cFinancial class
cFinancial financial = new cFinancial();
// Load it with data
financial.Principal = mPrincipal;
financial.Rate = mRate/100.0;
financial.Years = mYears;
financial.N = mN;
// Calculate the new value of the investment
mAmount = financial.Amount();
Reusability
As you may have figured out by now, the cFinancial class is highly reusable. If you look at the code in the cFinancial class, you will notice that it contains no references to the CompoundGrowth form. If you replaced the CompoundGrowth form with a completely different form, the cFinancial class would not have to be changed. That is one of the features of a good code library -- it has no specific knowledge of the software that is using it.
Summary
You can find a copy of the Interest Calculator Code on my Article Support Page.
In this article I discussed how C# solutions can be divided into data handling projects and presentation (display projects. In the InterestCalculator program the InterestCalculator project handles presentation and the FinancialLib project handles data. The FinancialLib project creates a data handling library that any other presentation project could use without modification.
Related Tags: data, microsoft, reusable, project, solution, presentation, form, library, startup project, visual c#
Sam Mela runs a math tutoring business in Springfield Virginia. His web site is http://www.WeekendSuccess.com
Your Article Search Directory : Find in ArticlesRecent articles in this category:
- Improper Way Of Marketing Reflects Poorly On A Company.
New business, product or service everything requires visibility, awareness in order to come into the - Replacing Paper Prints With Online Versions
Nowadays saving out on resources and being additionally informative are both aspects that are in. In - Stop Smoking Effectively
If I told you of a way that you could stop smoking harmful tobacco would you believe it? Most people - What Is Runtime Error 182? And How To Fix It
Are you finding an effective way to fix runtime error 182? Do you think fixing runtime error 182 is - Do You Know How To Fix Runtime Error 87 In Minutes?
Are you finding an effective way to fix runtime error 87? Do you think fixing runtime error 87 is to - Knowledge About Avi, Avi Player, Avi Converter On Mac
Knowledge about AVI, AVI player, AVI Converter on MacWhat is an AVI?AVI, an acronym for Audio Video - Buy Your Highly Successful Email Survey Software Today
Email Survey Software- Boost Your Business and Increase ProfitsAn email survey software could be one - Xrm - The Anything Relationship Management Solution
I recently attended the Microsoft Dynamics West Region FY11 Sales Planning Retreat. This year's meet - What Are The Benefits Of Working With Electronic Medical Records
Recording medical information is a vital part of health care services. These records are necessary f - Basic Factor To Make Website Business Oriented
Internet is home for millions of websites. The online business is becoming more and more competitive
Most viewed articles in this category:
- Parental Control Software
Parental control software is software that can help parents protect their children when they are onl - Digital Asset Management Software
Managing and organizing your organization's documents is a critical component to your business's suc - AdobeRGB vs. sRGB
Understanding color spaces I'll try to explain it very simplified, but understandable for everyone - Confessions of a Prankster
I wanted to get a jump on April Fool's Day, partially because of the long, cold winter blues, and pa - Malicious Thoughts About The Spyware Ills Of My PC
Who would think I was capable of such revengeful thoughts about the parties responsible for inflicti - Recover File and Recover Deleted File Tools
Data recovery software is a very effective way of retrieving data from a worn or damaged hard disk d - Life without Windows
Ubuntu, a user-friendly version of Linux, has been running so nicely on my home PC that I decided to - What Benefit Does an Online Software Download Site Offer You?
Are you having a problem that where you find a good softeware when you consider to have a try or wan - Maintaining A Website
There was an era when people were talking about how to create a website using html coding or some ea - Benefits Of Proper Time Tracking
Have you ever written down time when you have started and finished your work? Maybe you have had mul