473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2232
lk******@geocit ies.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******@geocit ies.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: "Refactorin g -
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******@geocit ies.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******@geocit ies.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.c om> 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*******@askm enoquestions.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 findACureForCan cer () { ...}

function balanceFederalB udget () { ... }

function endWorldHunger () { ...}

function doEveryThing ()
{
findACureForCan cer ();
balanceFederalB udget ();
endWorldHunger ();
}
} # ssalc
$happiness = new doEverything ();

Jul 16 '05 #10

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

Similar topics

8
2441
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 Writes: 1 Duration: varies from 1 to 30
7
11651
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 | +---------------+ | body | | (scrollable) | +---------------+ | footer |
55
4205
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 with this sort of thing? I know some of these potential users are with big companies and am wondering if anyone had real problems with that.
12
6073
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 that was required was a clean reinstall. This time, I found several possible solutions in Maxtor's knowledge base, particularily Answer 2352 - which notes that .NET 1 broke the
15
2568
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 ! ) what is it supposed to do ?
16
2537
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
3
2632
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 : +-----------+------+-------+ | folder_id | rack | date |
409
11051
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 objects that are more than 4GB long. The problem is, when you have in thousands of places
2
3577
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 uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.