473,320 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

problems are obvious in retrospect - writing OO being an example

I asked a lot of questions in May about how to organize OO code. I
didn't get great answers here, but someone here suggested that I look
the Eclipse library, which was a good tip. Looking at its small,
simply objects was an education for me.

What I was wondering, when I rewrote my cms from procedural code to OO
was how to avoid end up have every class called by ever other? I was
writing massive objects where every object needed every other object.
It was a mess.

In the end, I realized that the objects I was writing were too big.
Again, looking at the Eclipse library brought this home to me. What I
learned can be distilled to this:

Write pebbles, not boulders. Small objects, not big objects.

Eventually I feel like I finally "got" OOPs programming: that portion
of my objects that did not need some other object then became the base
class that other classes were built on. For instance, the portion of
my forms class that didn't need any other class became my base forms
class. But then where I needed the $sql database class to get info to
fill out some forms, I created a child class of forms, and the child
combined the database class with the base forms class.

It's all obvious in retrospect, but it was opaque to me back in May.

I write this as a lesson for others struggling with the same issue I
struggled with.
Jul 16 '05 #1
11 2194
lk******@geocities.com (lawrence) wrote in
Eventually I feel like I finally "got" OOPs programming: that portion
of my objects that did not need some other object then became the base
class that other classes were built on. For instance, the portion of
my forms class that didn't need any other class became my base forms
class. But then where I needed the $sql database class to get info to
fill out some forms, I created a child class of forms, and the child
combined the database class with the base forms class.

What do you mean "combined"?

class database extends forms?

Jul 16 '05 #2
brian wrote:
lk******@geocities.com idiotically stated:
I write this as a lesson for others struggling with the same issue I
struggled with.


Then would you say, at some point, OO just isn't the right solution for
some
projects? From what you said, it seems that to finally write "good" OO,
it just got insanely encapsulated to a point that going back to procedural
php is just simpler and easier.


Personally I think OO php works well if you have a largely hierarchical class
structure, with simpler classes aggregated into larger ones, to hide functionality,
data, etc as per "The One True Way (tm)" - if you can do
$Admin->ValidateDdata();
and the $Admin object will call member objects, or use other classes transparently
to its caller, that's great; if everything is calling everything else in some
kind of byzantine spider web, it's probably not a great design, or something that
could be done better in some other language...
Jul 16 '05 #3
matty wrote:
... if everything is calling everything else in some
kind of byzantine spider web, it's probably not a great design, or something that
could be done better in some other language...


Doesn't mean that it would be any better in another language.

Martin Fowler has written a great book on the subject: "Refactoring -
Improving the Design of Existing Code"

If you apply the advice from that book to your code and go through with
it, I think that any "spider web" can be transformed into a nicely
structured and layered OO application - without ever being in a state
where it doesn't run.

Jochen

--
/**
* @author Jochen Buennagel <zang at buennagel dot com>
*/

Jul 16 '05 #4
brian wrote on Wednesday 20 August 2003 13:12:
lk******@geocities.com idiotically stated:
I write this as a lesson for others struggling with the same issue I
struggled with.


Then would you say, at some point, OO just isn't the right solution for
some
projects? From what you said, it seems that to finally write "good" OO,
it just got insanely encapsulated to a point that going back to procedural
php is just simpler and easier.


Few years back I wrote down some thoughts about OO and software development.
Maybe it's relevant here and maybe some would like to read it. I never
actually acted on those opinions because of lack of time on my hands.

http://www.welikeyou.com/pide/process-based-ide.html

In short, I don't see OO as well-suited for most software development;
instead, I think development should be based on processes.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 16 '05 #5
Jochen Buennagel wrote:
matty wrote:
... if everything is calling everything else in some
kind of byzantine spider web, it's probably not a great design, or
something that could be done better in some other language...


Doesn't mean that it would be any better in another language.


I didn't say it would be! ;p The point was more, that if you
*have* to jump through ridiculous hoops to implement it in PHP
*because of the language*, it might be better to do it in something
else.

You normally can do it OK in PHP, but there do seem to be cases where
it's a bit artificial
Jul 16 '05 #6
lawrence wrote:
I asked a lot of questions in May about how to organize OO code. I
didn't get great answers here,
<comp-object>'here' meaning c.l.php</comp-object>

You'd probably have more answers on an OO ng, like comp.object, but
would it have help you much at that point ? Some concept are better
learned by experience, and basics of code structure - be it procedural,
functional or OO - is one of them IMHO.
but someone here suggested that I look
the Eclipse library, which was a good tip. Looking at its small,
simply objects was an education for me.
Yep, good working exemples are a great help.
What I was wondering, when I rewrote my cms from procedural code to OO
was how to avoid end up have every class called by ever other? I was
writing massive objects where every object needed every other object.
It was a mess.
Indeed...
In the end, I realized that the objects I was writing were too big.
Again, looking at the Eclipse library brought this home to me. What I
learned can be distilled to this:

Write pebbles, not boulders. Small objects, not big objects.
Right. Absolutely. Or, to be more accurate : dont make object biggers
than they should be to be cohesive - but not smaller.

Note that this principle may also apply to functions/methods, and even
whole programs !-)
Eventually I feel like I finally "got" OOPs programming:
You are a very happy man !

I started learning programming with OO languages, almost always tried to
favor the OO approach (even if not always applied it), and I still
wouldn't claim I 'got' OOP. Yes, I believed I had once I understood the
very basic concepts of classes, instances and inheritence. But there's
much more to OO than just using classes and inheritence.
that portion
of my objects that did not need some other object then became the base
class that other classes were built on.
Woop. They're one thing clear in this, it's that you (re)discovered some
principles of dependency manangement. But the end of the sentence is not
quite clear to me. Could you elaborate ?
For instance, the portion of
my forms class that didn't need any other class became my base forms
class.
Well... The base 'form' class should be the one factoring common
behaviours and attributes of all 'form' classes (and still this may be a
pretty simple-minded approach). The fact that the base 'form' class
depends on others or not has nothing to do with it.

May I give you an advice ? Read about some basic OO concepts - like for
exemple the Dependency Inversion Principle (but there are some others,
and they all work together...).
But then where I needed the $sql database class to get info to
fill out some forms, I created a child class of forms, and the child
combined the database class with the base forms class.


How did you 'combined' two classes, in a language that don't allow
multiple inheritence ? By composition ?

Well, this all seems a bit OT here, so crosspost and fu2 comp.object

Bruno

Jul 16 '05 #7
brian wrote:
lk******@geocities.com idiotically stated:

I write this as a lesson for others struggling with the same issue I
struggled with.

Then would you say, at some point, OO just isn't the right solution for some
projects? From what you said, it seems that to finally write "good" OO, it
just got insanely encapsulated to a point that going back to procedural php
is just simpler and easier.


OO main goal is not IMHO to reduce complexity, but to help manage it by
reducing dependencies. And writing 'good' OO code is not necessarily
'insanely encapsulating' all and everything - which is just that :
insane-, but more about capturing the invariant and hiding the rest in
the right place.

Now I agree that some things may be better done in good ole procedural
code !-)

Bruno

Jul 16 '05 #8
Zurab Davitiani <ag*@mindless.com> wrote in
Few years back I wrote down some thoughts about OO and software
development. Maybe it's relevant here and maybe some would like to
read it. I never actually acted on those opinions because of lack of
time on my hands.

You argue that just because there are objects in the real world, we
shouldn't be tied to them in programming. But an "object" in a program
isn't real. It's a logical construct. And the analogy to objects in the
real world is just that -- an analogy, nothing more.

They could have chosen a different analogy. Heck, they could have
called them "virtuals" or "dreams" instead of "objects". We'd have
"Dream Oriented Programming", DOP instead of OOP. And where would your
argument be then?

You also failed to explain how your idea of process oriented
programming has advantages over OOP. And how does it address the real
programming problems OOP was invented to address.

For instance, you give a good example of how an object might be built
to deal with converting variables of different types to strings. If you
looked at that as a process, what advantages would be gained.
Jul 16 '05 #9
matty <ma*******@askmenoquestions.co.uk> wrote in news:3zR0b.9737
You normally can do it OK in PHP, but there do seem to be cases where
it's a bit artificial


I don't know... I'm kind of skeptical. Are you saying php's object
implementation is lacking when compared to other OOP languages or that
OOP is not a panacea?

Well, I'm kind of skeptical either way. I guess there are some minor
things about the way objects are implemented in php that are a
hinderance. Perl has that really cool hash thing going where objects
are essentially overloaded associative arrays. But , I dunno... php
seems alreight to me. If I had to say which OOP implementation was
better I'd be hard pressed.

And I wouldn't *really* say OOP is the answer to *ALL* programming
problems but I find it hard to believe there are many real world
situations where it would be a hinderance. It's almost inconceivable
because an object can be nothing more than a group of variables and
functions -- related or not. Which is really what a traditional program
is anyway. You could just write your constructor function like you
would main () of your C program.

class doEveryThing
{
function findACureForCancer () { ...}

function balanceFederalBudget () { ... }

function endWorldHunger () { ...}

function doEveryThing ()
{
findACureForCancer ();
balanceFederalBudget ();
endWorldHunger ();
}
} # ssalc
$happiness = new doEverything ();

Jul 16 '05 #10
John Heim wrote:
I don't know... I'm kind of skeptical. Are you saying php's object
implementation is lacking when compared to other OOP languages or that
OOP is not a panacea?
Well, it is actually lacking compared with Java (or Perl even for that
matter), but that doesn't stop PHP being an excellent platform for
web applications. Continually-running processes in Perl/Java can have
the edge sometimes, but yes, I think PHP is brilliant. (Perl does
have speed advantages sometimes though)

Certainly, the PHP5 OO sounds like it addresses most of the issues I
have with PHP's OO as it stands.

And I wouldn't *really* say OOP is the answer to *ALL* programming
problems but I find it hard to believe there are many real world
situations where it would be a hinderance. It's almost inconceivable


Me neither. (Although there are times when speed considerations win out,
but those are "border" cases). I was more posting a hypothetical scenario -
given that a system is written in an OO manner, it may be the case that
PHP's incomplete OO support forces various kludges to keep the code OO. I've
yet to find a scenario like this, and most of the bad php OO stuff I've seen
out there is down to the coder, not the system requirements.

Jul 16 '05 #11
John Heim <jo******@nospam.tds.net> wrote in message news:<Xn****************************@144.92.9.81>. ..
lk******@geocities.com (lawrence) wrote in
Eventually I feel like I finally "got" OOPs programming: that portion
of my objects that did not need some other object then became the base
class that other classes were built on. For instance, the portion of
my forms class that didn't need any other class became my base forms
class. But then where I needed the $sql database class to get info to
fill out some forms, I created a child class of forms, and the child
combined the database class with the base forms class.

What do you mean "combined"?

class database extends forms?


Yes, till I read the book "Effective Java". It is a book full of
advice that can be applied to any OO language. One of their chapters
is "Favor composition over inheritance." My new approach is that I
only use inheritance for "interfaces", and I use composition for all
else. (Of course interfaces don't really exist yet, but I write base
classes with no implementation, which should be pretty easy to make
into real interfaces once my company feels comfortable writing to PHP
5.)

--Lawrence Krubner
www.krubner.com
Jul 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: DK | last post by:
I have a SP that I use to insert records in a table. This SP is called hundreds of times per minute. Most inserts complete very fast. And the profiler data is as follows: CPU: 0 Reads: 10...
7
by: Matt Kruse | last post by:
This is a typical layout, but I have specific requirements. I'm trying to figure out a) if it's possible to meet the requirements and b) if so, how. +---------------+ | header |...
55
by: drhowarddrfine | last post by:
I'm working on a web site that could use some control using js but am concerned about what problems I may have with potential users having their js turned off. Has anyone had any serious problems...
12
by: leroykl | last post by:
Some history, I have a Maxtor OneTouch II USB 2 backup drive with Retrospect Express HD. I recently found that Retrospect Express HD hangs at Updating Status. This has happened before, and all...
15
by: Ian Bush | last post by:
Hi All, I'm a bit confused by the following which is causing one of our user's codes fail in compilation: typedef struct SctpDest_S; 1) Is this standard ? 2) If so ( or even if not so ! )...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
3
by: Thorben Grosser | last post by:
Hello Newsgroup, I am doing some archive database and therefore got one table indexing every folder and one table storing which rack belongs to which department, eg: table folders :...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.