Content

Hardwiring: programming the design (tech)

submitted on 24th Mar 2008. A part of Articles.  submit an article

written by owen

There is a tendancy to write your use case directly into the low level design of the code. This pattern should be avoided as much as possible because it results in extensive "recoding" whenever high level design changes are made to the program. The highlevel design is not caved in stone and will most likely change as the system evolves but its core design rearly changes. It is important for the programmer to identify this core design.

For example an extreme case can be seen when the previous programmers wrote a screen for the 10 department types that are in the system - assuming that there would only be 10. As you can see hardcoding or hardwiring your use case rules into your code is not a good thing. The programmer wrote the code on the "business logic" instead of the "system layer".

It is important to notice that there is a system below the business logic. This system is what keeps the application simple and stable. The programer should seek to find the best way to rewrite the highlevel business logic into a stable sub system.

Take for instance the previous example: you can imagine that the programer got a use-case with 5 rows and 2 column of 10 items. The programmer looked at the first line of the use case and started coding right away (and in truth and in fact probably coded it in half the time that I would take to code it). The end result will work and will have the same output but the difference between the 2 approachs to the problem is night and day. Further down in the project the need MAY arise to add a new type of department. You should notice that the business logic in the use cases DOES NOT BREAK but the code that was written to implement the use case fails and the blame goes on the programmer even though the programmer did what the use case said should be done.

Another example: bank type. You notice that the use cases specify particular actions that occur on certain types of banks. And these types of banks are hard coded into the system. Business logic constants are bad design. This implementation is done like so:

BANK_TYPE1 = 1

SELECT * FROM BANKS, BANK_TYPE WHERE BANK.TYPE_ID = BANK_TYPE.ID AND TYPE = [BANK_TYPE1]

IF BANK.TYPE == BANK_TYPE1 THEN

        DO BUSNIESS LOGIC

END IF

The shortfall of this type of programming is the SAME as the 10 item example above. If for instance a new bank type is added that implements the same business logic as that of BANK_TYPE1 then the code will have to be CAREFULLY altered to facilitate the change to the design. Here is the new code:

BANK_TYPE1 = 1

BANK_TYPE_TWO = 3

SELECT * FROM BANKS, BANK_TYPE WHERE BANK.TYPE_ID = BANK_TYPE.ID AND TYPE = [BANK_TYPE1] or TYPE = [BANK_TWO]

IF BANK.TYPE == BANK_TYPE1 THEN

        RETURN (BANK_TYPE1) BUSNIESS_LOGIC1()

END IF

IF BANK.TYPE == BANK_TYPE_TWO THEN

        RETURN (BANK_TYPE_TWO) BUSNIESS_LOGIC1()

END IF

In the best case senario the same programmer will be able to remember how the program works and change all the places that need to be changed to fix the problem.

The solution to this problem requires a system level design change that will protect the code (the programmer) from changes/enhancements to the design. There are many ways that this can be done and the best way often takes more time and therefore the benefits of such an change must be evaluated during development by the programmer.

---

The point here is that it that the use cases are not low level designs. The progammer should ( whenever possible ) try to abstract the effects that changes have on the code which is written, by writing it in a way such that it is flexible enough to absorb business logic/design changes that may occur in the future.

permanent link, visited 120 times.

comments

  1. So give us an example of how you would have done that with the bank_type_case nuh?

    by mad bull ( Mon, 24th Mar at 9:08 pm )

  2. The objective of the article is not to identify a particular solution but to identify a particular problem which occurs when applications are being developed.

    reply by owen (Tue, 25th Mar at 12:50 am )

  3. Owen, mi breddah, you sound like Motty Perkins. You like to fire up people with big talk about the problems, but you won't try to find the solutions.       

    reply by mad bull (Tue, 25th Mar at 8:39 pm )

  4.       , one solution is to use a sub system of flags on the BANK.TYPE table that indicate which pieces of buisness logic to execute on each type of bank. Therefore when development is complete and additional bank types or business logic are required, they can be added to this "sub-system" without heavy hacking. Its a form of "future proofing". Should I add a solution code to the article?

    reply by owen (Wed, 26th Mar at 11:30 am )

  5. No to the sollution code, I was just wanting to see the ideas. The one you've given could work. Any others?

    reply by mad bull (Thu, 27th Mar at 10:16 pm )

  6. the solution often hangs on the language, type of database, old code, new code and the amount of time avaliable. If the system is already built bad then you are looking at a whole other ball game. The aim is to always write a program that accepts change readily without headaches and retesting.

    reply by owen (Thu, 27th Mar at 10:54 pm )

  7. Dude, did I click the wrong link? I feel like a stumbled into a programming class.

    by Leon ( Wed, 26th Mar at 12:58 am )

  8. me and u both Leon :S

    by Irie Diva ( Wed, 26th Mar at 3:41 pm )

  9. I was under the impression that putting (tech) in the title would be enough but I guess I'm going to have to spell it out. I would suggest you look at the recent updates page for less "technical" stuff.

    reply by owen (Wed, 26th Mar at 4:52 pm )

  10. Hey Owen, do you write C? I have a bredrin in Jam, he is looking to subcontract out a portion of his project which must be done in C. Let me know!

    by mad bull ( Thu, 27th Mar at 10:19 pm )

  11. wow is it a game, or a operating system? give him my email addy, tell him to send me some info on it

    reply by owen (Thu, 27th Mar at 10:28 pm )


Post your comments on this article


add picture, your website and other options

More or less

What did you do for mommy? 1 by Tami

Working from beyond 1 by Tami

Downtown 2 by owen

Daymoon 2 by FlyingV

Dog 1 by owen

Info

JAMAICA FREE Classifieds

There have been 0 new comments since yesterday.


Lalalala, Keep doing your thing, lalalalalala. - Tami ( Kingston, Jamaica )


I came across yoursite today. And I've read through everything in your archives. Really love the site. I'm officially addik-ted. You're now my sole daily read. Now I know what digital weed is like. :-) - Kaschief ( Kingston, Jamaica )


Owen, you constantly amaze me with your site redesigns. :) - Taran ( San Fernando Trinidad and Tobago )


Nice and clean .. probably one of the better Jamaican sites out there period, except mine ofcourse :) .. Love the css .. - DannyB ( Kingston, Jamaica )


Hi Owen, long time, no see. Good luck with Dean, from what I can see on the maps it's coming in now. - Vegard ( Oslo, Norway )


Owen, Your site is pretty interesting and original, but you should have someone do a spell check before you upload. Good Luck! - Cherry ( Kingston )


Just browsing....an interesting read..... - Jamila ( Barbados )


We were just wondering where we could purchase our very own Owensoft... we're planning on staging a mudwrestling match between it and our Microsoft...winner gets to take on Adobe Acrobat Reader (which has been known to fight DIRTY let me tell you). Thanks for visiting our site, Lori and Cutcha - Lori and Cutcha ( San Diego, CA )