On The Web by Ircmaxell
GNU/GPL PageCache Joomla! APC php5 Lighttpd! Redhat
Home arrow Articles arrow OOP and Abstraction, When is enough, enough?
Friday, 25 July 2008
 
 
Featured Site
Main Menu
Home
Articles
Services
Portfolio
Version Information
Bug Tracker
F.A.Q.
Downloads
Forum
Contact Us
Text Link Ads
Latest Version
Feed Icon Page Cache 1.0.8 stable
Release Date: 2007-06-11
Donate!
Login
Syndicate
OOP and Abstraction, When is enough, enough?
User Rating: / 0
PoorBest 
Written by ircmaxell   
Tuesday, 19 June 2007

        In my programming endeavors, I've come across all sorts of coding styles, from extreme OOP to simple structured programming.  One thing strikes me as apparent:  Neither is the correct path.  Now, don't get me wrong, both OOP and structured programming have their advantages, but both have disadvantages as well.  The problem comes when a programmer sticks only to one style when the situation doesn't really dictate that style.  From a simple development point of view, both look like equal alternatives (depending on your programming style).  The problem really comes into view with maintenance and expansion. 

        Structured programming can be great for easy tasks (such as creating a link in a web page).  The drawback of simple structured programming is that for common tasks (say, database interaction or templating) it creates overly long and hard to follow code.  Not to mention the time that it takes to constantly rewrite needed code.  Now, don't get me wrong, structured programming has a very important place in any programmers toolkit. 

        Object Oriented Programming is great for common tasks (such as database interaction and templating) because it provides a common framework.  Imagine creating a program that needs to connect to two RDBMS during one instance of the program.  To do that in structured programming, you would need to keep track of each database link (if your language supports multiple connections), and make sure each link is used properly.  Using OOP, you could just create two instances of the same db object.  So instead of

$link1 = mysql_connect('localhost');
$link2 = mysql_connect('123.123.123.123');
if(($result = mysql_query($sql1,$link1)) === false) die("There was an error, ".mysql_error());
if(($result2 = mysql_query($sql2,$link2)) === false) die("There was an error, ".mysql_error());

OOP would let you do something like this

$db1 = new database('localhost'); 
$db2 = new database('123.123.123.123'); 
$result = $db1->query($sql1); 
$result2 = $db2->query($sql2);

        Now, the point of this article is not that one style is better than the other.  The point is that NEITHER is perfect.  The complexity that OOP can create completely clouds a simple task.  A simple search function should not take 8 different classes (2 parents and 3 children each) to complete.  There is a tradeoff between ease of programming, performance and maintainability.  One thing (from my experience) that many programmers need to learn is when is abstraction abstract enough?  Should we create a class "link" that builds all HTML links?  Every link that you want to output would be created as a new instance of the link output?  Sure, that could have its advantages (in terms of compliance between different specifications such as XHTML and WML), but is it necessary for 99% of programs?  NO.  Don't make things any more complex then they need to be.  Who knows who will need to come in and clean up the mess when something goes wrong...

Trackback(0)
Comments (0)Add Comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

security code
Write the displayed characters


busy
Last Updated ( Tuesday, 19 June 2007 )
 
Next >
Loans - Credit Card - Car Insurance - Internet Marketing
 
Top! Top!
Generated in 0.94342494010925 Seconds