Page 4 of 4
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 5:40 am
by Eran
If I can add a little more - OO design and implementation is something that is hard to teach, but more something you have to get through experience. I distinctly remember the transition I went through when I started out with OOP, and in the beginning I wrote it very similar to how you write it now.
There is no 'increased planning and development time' if you are familiar enough with the methodology. If the task at hand is simple enough you can start solving it immediately, if it's complex you may plan a little - no different then with procedural programming. The amount of time spent before actual 'coding' takes place is proportionate directly to the experience / skill with the methodology and with the problem domain.
I very much recommend you to start reading about design patterns and their application for solving common development problems.
Jcart wrote:My take: OOP has very little to do with the code, it's all interface baby.
When you feel this quote in your bones, you would have understood what OOP is all about

Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 8:34 am
by Benjamin
I have read about design patterns before and I have a pretty good grasp of them. Would anyone like to show me a model (as in prime example) of a high quality and useful interface?
As a simple example; I understand that I can have a object that represents an image with attributes such as the location, height and width. I can then pass this object to other classes which can perform actions using data it retrieves from this object. I could pass it to a class which would calculate a new size, or I could pass it to a class that performs the resizing. Does this mean that I should pass the resize class an instance of both the image and the class that calculates the new size?
If I write code this way, does that lock me into having to write all the code this way?
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 9:50 am
by Ollie Saunders
I believe you are saying that the point of OO isn't for reusability because OO allows you to apply things to more varied scenarios and because reusability is much more complex.
Yes, OO helps but it's by no means the whole solution. AOP helps some more, packaging and package management helps more on top of that but above all reusability is about identifying generics.
But as I said before reusability is true of functions alone. You are identifying generics when you decide which parameters a function will take (and we are talking scalars for these parameters, not objects). And these will determine how that function can be reused. You've made a decision of how the users of that function will be able to vary it's behaviour. OO lets you do that at a higher level but you still have to identify those points of parameterization or "flex points". So to achieve reusability you have to be good at identifying those generics or even better, work in a way that allows you to try and test those assumptions of what the generics are and change them if they turn out not to be correct. Reusability is hard to achieve because very often there are a great many of these generics. If you've ever tried to cater for them all (I did) you will never finish! And what's more you'll end up (taking the function example once again) with 8, 10 or more parameters.... no-body would use such a function because writing it from scratch would be easier. So you have to pick the most important flex points, settle. If you've written good OO the user of your code should be able to add new code to cater for everything else. Even still the creation of reusable code is a very long process and hard to get right.
If that is the case, why would someone want an OO framework?
Because you can create flex points that are more complex than just parameters to functions and let's face it many of them are. Additionally it makes it easier for other programmers to build on top of your code base by overriding bits or hooking in their own, new code.
Wouldn't they prefer a framework that contained a library of easy to access reusable code that they could use on a variety of projects?
Of course, are you implying that functions are easier to reuse? Well this may be true just because they are simplier but for problems where parameters aren't sufficient as flex points functions can't cope.
Consider that the framework in this case would allow OO programing on top of the predefined library.
That's great, a perfectly legitimate framework for sure. I have written a library (fluidics) that as long as you are confident that the flex points of what you are trying to make reusable are simple enough to only require variance by parameters and you have catered for those flex points.
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 11:13 am
by Christopher
Jcart wrote:My take: OOP has very little to do with the code, it's all interface baby.
I agree, but it does lead to the question, "An interface to what?" There has to be a
something to have an interface to. Interface is the second O in OOP...
Focusing on the code is first among the problems of Procedural programming. Focusing on the interface is a step in the right direction. You really want to understand the Domain first, then develop the Interface to it, last is the the code.
Hmmmm ... what does that development process sound like ...

Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 3:39 pm
by sike
hey,
seems like the discussion is stuck so i thought about the simplest interface that represents the basic ideo of oop (in my opionion) that i could show. I settled on the interface for a basic iterator because i think it shows the two main ideas in oop (debatable i know) :
1) The interface is as abstract as it can be
2) It's highly cohesive
Code: Select all
public interface IIterator
{
/**
* Resets iterator to its initial state
*/
function reset():void;
/**
* Returns true if the iteration has more elements.
*/
function hasNext():Boolean;
/**
* Returns the next element in the iteration.
*/
function next():*;
}
the result of that design is obvious : it is highly reusable and it simplyfies your code alot . it offers you a consistent way of doing a single thing (and only that) : iterating over a anonymous collection of things.
cheers
Chris
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 3:49 pm
by VirtuosiMedia
So would another way of saying it be that oriented part of OO refers to a consistent method naming schema for similar objects through the use of an interface?
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 4:03 pm
by Christopher
No ... and I was taking a little literary license to make a point ... that point about oriented and interface is that with OOP you provide a code interface to the data, with Procedural you provide a code interface and pass the data to it. Seems like as small difference, but the ramifications of that difference are what lead to all the other benefits, methodologies, patterns, etc.
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 4:59 pm
by VirtuosiMedia
arborint wrote:No ... and I was taking a little literary license to make a point ... that point about oriented and interface is that with OOP you provide a code interface to the data, with Procedural you provide a code interface and pass the data to it. Seems like as small difference, but the ramifications of that difference are what lead to all the other benefits, methodologies, patterns, etc.
I guess I'm still struggling with the concept a little. I get that throwing code into a class and being able to reuse it doesn't automatically mean that it's OOP, but could you point to a concrete example, perhaps one that does something simple in procedural code and then does the same thing in OO manner? Having something to compare the two would be very helpful.
Re: OO Usage Discussion
Posted: Wed Jun 18, 2008 5:49 pm
by Christopher
Think about the Procedural version of sike's code:
Code: Select all
unset($myarray);
while (hasNext($myarray)) {
// do something
next($myarray);
}
That doesn't look so bad...
Re: OO Usage Discussion
Posted: Fri Jun 20, 2008 10:31 am
by EffingHell
ole wrote:The point of OO isn't really reusability.
Well, it was one of the 'selling points'.
Good conversation on the topic can be found here:
http://c2.com/cgi/wiki?ReuseHasFailed.
Re: OO Usage Discussion
Posted: Fri Jun 20, 2008 12:20 pm
by Christopher
I agree that usability is one of the selling points of OOP. Inheritance and composition are two of the new ways that OOP improves reuse.