Breaking Down Programming Problems
by
on 02-05-2009 at 11:06 AM (333 Views)
Breaking Down Programming Problems
So, when I have an Assignment, or I need to create some software, or am presented with a problem, my first reaction is, 'WOA! This seems too complicated'... but being something that I really have to do I have to make it. I don't use any DSDM or methodologies, they take too much time to make and I don't have all that time to make an assignment, because generally I am very restricted.
So I start with reading the scenario and make a clear picture in my mind of what the result should look like and what are the functionalities of the end project. I first start by breaking down the scenario into pieces.
For this example I will take a simple banking system, in case you are asking (if you read my other blog) yes, I seem to use the banking example all the time, it's because it's something basic and that everyone knows it's basic functionalities without having to blog about the scenario. But in this case I will use a simple ATM which you can withdraw and deposit cash on.
I will start by braking it down into some simple points, which are:
Users (Clients) -> PIN -> Login
Accounts -> Balance -> Withdraw / Deposit
These are the main functions / features that this ATM will need to work. Afterwards I will think about the basic logic behind it:
A User (Client) will have one or more Accounts, to use the account he will need a PIN to login. When he logs in he can withdraw from his balance. If balance is 0 he cannot withdraw, or if the amount he wants to withdraw is more than the account balance an error will be shown.
Basically that is the main idea. So, after that I will start creating / designing the classes.
So mainly there are 2 classes that we already mentioned before... The Users and the Accounts. So, we create the classes and make the required fields / variables and methods. In this case we will create:
Account:
Variables - double Balance
Methods - Withdraw(double amount), Deposit(double amount)
User:
Variables - int PIN, List<Accounts>
Methods – Login (int insertedPin)
(Please note that this is just a rough outline of the system)
So basically now I solved the problem. I know how it will work exactly, so if you know some basic coding you are ready to go, with some if statements and you have a working program.
The next thing is, what if the user inputs anything that is not a valid double, such as “hello” or what if he tried to withdraw $ -100, or if he tried to deposit $ -100? We should take care of this either by a general try catch in the method, or handle them with some if statements. It’s up to you actually, but a simple try catch will work just fine!
Well, I guess that’s it. I don’t write this on paper or anything, I usually think of all this as soon as I’m reading and understanding the scenario, and I start designing and coding straight away, and then take care of the exception handling.
I hope that this simple example will let you understand how to approach complicated programming questions. Once you use this, it’s not that much complicated… and for small projects you don’t need to use any Methodologies or anything that much complicated, only an extra effort to think a little bit more…









