Day 1

Why Object Orient Programming?

A lot of programmers start learning their skill of programming using BASIC, C or Pascal. These are called 3th. generation languages or procedural languages. The approach they take to solve a problem is procedural. This means the solution is step by step, one follow others. Blah, blah, blah,... You already learn all these in your class or books. What you really interested is why we have to create a program using OOP instead of procedural approach.

Let look into this with a small example. Take a look at the following example.

"One day, you were approached by a friend to build a system. He need a simple program that can help him to keep track of the balance of his clients' account. His clients save and borrow money from him and he need a system to record down when they deposit/withdraw money, He need a report that show the information of the client, the balance of the account and the transaction on that account. He will also need a report that show all the deposit/withdrawel in a certain period."

As an experince C programmer, you think you can do the coding in 2 days and finish the project in a week. So you start the more detail study and start your design and coding. After the system study, you come to the conclusion as follows.

  1. One client has only one account.
  2. The balance of the an account can be in positive/negetive at any time.
  3. There are about 20 clinets and about 40 transactions in a month.
  4. The amount of client is expected to increase to 50 in another 5 years.
To make life easy, you decided that you won't use any database. Instead, you use a flat file format to store data.
The other thing you ommited is the backup and cleaning the transaction file. You assume that the harddisk is big enought until the next upgrade that might be in the next 3-5 years.

So, you spend 1 day to design the system and another 2 days for coding, 1 day for testing and 1 day for documentation. (Just nice, 5 working days a week.)

You system you build might be as follow:-
 

You use 2 structure to represent the two entities, "struct Account" and "struct Transaction".

struct Account{

int iID;
double fBalance;
char sOwnerName1[50];
char sOwnerName2[50];
char sOwnerAdd1[50];
char sOwnerAdd2[50];
char sOwnerAdd3[50];
char sOwnerTel1[20];
char sOwnerTel2[20];
};

struct Transaction{

time_t tTimePosted;
int iAccID;
double fAmount;
char sRef1[50];
char sRef2[50];
};

Below is the source file  source01-01.zip 1