What is/is not considered to be good OO programming

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Marston

    What is/is not considered to be good OO programming

    Several months ago I started a thread with the title "What is/is not
    considered to be good OO programming" which started a long and
    interesting discussion.

    I have condensed the arguments into a single article which can be
    viewed at


    I fully expect this to be the start of another flame war, so sharpen
    your knives and get stuck in!

    Tony (you do it your way and I'll do it better) Marston
    This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

  • Jochen Daum

    #2
    Re: What is/is not considered to be good OO programming

    On 3 Dec 2003 05:30:25 -0800, tony@marston-home.demon.co.u k (Tony
    Marston) wrote:
    [color=blue]
    >Several months ago I started a thread with the title "What is/is not
    >considered to be good OO programming" which started a long and
    >interesting discussion.
    >
    >I have condensed the arguments into a single article which can be
    >viewed at
    >http://www.tonymarston.net/php-mysql/good-bad-oop.html
    >[/color]

    Thats great. I'll be reading it after my holiday and possibly contact
    you by email, if you don't mind.

    Jochen
    --
    Jochen Daum - CANS Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    • J0hn Sm1th

      #3
      Re: What is/is not considered to be good OO programming

      Tony Marston wrote:[color=blue]
      > Several months ago I started a thread with the title "What is/is not
      > considered to be good OO programming" which started a long and
      > interesting discussion.
      >
      > I have condensed the arguments into a single article which can be
      > viewed at
      > http://www.tonymarston.net/php-mysql/good-bad-oop.html
      >
      > I fully expect this to be the start of another flame war, so sharpen
      > your knives and get stuck in!
      >
      > Tony (you do it your way and I'll do it better) Marston
      > http://www.tonymarston.net/[/color]

      Hey that's a really well written (or put together) document. I'll be
      saving that for good use.

      Comment

      • André Næss

        #4
        Re: What is/is not considered to be good OO programming

        Tony Marston:
        [color=blue]
        > Several months ago I started a thread with the title "What is/is not
        > considered to be good OO programming" which started a long and
        > interesting discussion.
        >
        > I have condensed the arguments into a single article which can be
        > viewed at
        > http://www.tonymarston.net/php-mysql/good-bad-oop.html
        >
        > I fully expect this to be the start of another flame war, so sharpen
        > your knives and get stuck in!
        >
        > Tony (you do it your way and I'll do it better) Marston
        > http://www.tonymarston.net/[/color]

        I just think it's funny that you still don't understand object composition.
        In your article you write: "How do you share code in OO systems? Through
        inheritance.", not even mentioning object composition. Object composition
        was also the crux of my argument, i.e.: where you see only inheritance, I
        see inheritance and composition. From this we can only deduce that you in
        fact did not properly understand my argument. That doesn't make the
        discussion any easier.

        But then again, most beginners in OOP face this particular problem, they
        overuse inheritance because that's usually the first thing they learn, and
        once they get the hang of it, they won't let go.

        André næss

        Comment

        • Philipp Lenssen

          #5
          Re: What is/is not considered to be good OO programming

          André Næss wrote:
          [color=blue]
          > Tony Marston:
          >[/color]
          [color=blue][color=green]
          > >
          > > I have condensed the arguments into a single article which can be
          > > viewed at
          > > http://www.tonymarston.net/php-mysql/good-bad-oop.html
          > >[/color][/color]
          [color=blue]
          >
          > I just think it's funny that you still don't understand object
          > composition. In your article you write: "How do you share code in OO
          > systems? Through inheritance.", not even mentioning object
          > composition. Object composition was also the crux of my argument,
          > i.e.: where you see only inheritance, I see inheritance and
          > composition. From this we can only deduce that you in fact did not
          > properly understand my argument. That doesn't make the discussion any
          > easier.
          >[/color]

          I was thinking the same. I saw the article, looked for "compositio n",
          couldn't find it, and went away.

          --
          Google Blogoscoped
          A daily news blog and community covering Google, search, and technology.

          Comment

          • Tony Marston

            #6
            Re: What is/is not considered to be good OO programming

            André Næss <andrena.spamre allysucks@ifi.u io.no> wrote in message news:<bqn4ko$3k l$1@maud.ifi.ui o.no>...[color=blue]
            > Tony Marston:
            >[color=green]
            > > Several months ago I started a thread with the title "What is/is not
            > > considered to be good OO programming" which started a long and
            > > interesting discussion.
            > >
            > > I have condensed the arguments into a single article which can be
            > > viewed at
            > > http://www.tonymarston.net/php-mysql/good-bad-oop.html
            > >
            > > I fully expect this to be the start of another flame war, so sharpen
            > > your knives and get stuck in!
            > >
            > > Tony (you do it your way and I'll do it better) Marston
            > > http://www.tonymarston.net/[/color]
            >
            > I just think it's funny that you still don't understand object composition.
            > In your article you write: "How do you share code in OO systems? Through
            > inheritance.", not even mentioning object composition.[/color]

            Because I have looked at definitions and examples of object
            composition and deduced that it would serve no useful purpose in my
            infrastructure.

            To quote one reference: http://www.eagle-software.com/object.htm

            "Object composition allows you to group components together, creating
            a new component."

            I do not see where I can use this technique, or what advantage it
            would bring, therefore I am not going to waste any time on it.

            To quote another reference:


            "The disadvantage of object composition is that the behavior of the
            system may be harder to understand just by looking at the source code.
            A system using object composition may be very dynamic in nature so it
            may require running the system to get a deeper understanding of how
            the different objects cooperate."

            As I do not like writing complicated software that is difficult to
            understand this whole idea sounds like a no-no to me. I prefer to
            follow the KISS principle.

            From the same article:

            "Most designers overuse inheritance, resulting in large inheritance
            hierarchies that can become hard to deal with."

            If you look at my code you will see that I do not have a large
            inheritance hierarchy. I have just one superclass and one layer of
            subclass, therefore you cannot say that I am overusing inheritance.

            [color=blue]
            > Object composition
            > was also the crux of my argument, i.e.: where you see only inheritance, I
            > see inheritance and composition. From this we can only deduce that you in
            > fact did not properly understand my argument.[/color]

            You argument is irrelevant as it serves no useful purpose when
            discussing a single abstract class.

            Tony Marston
            This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

            [color=blue]
            > That doesn't make the discussion any easier. But then again, most beginners
            > in OOP face this particular problem, they overuse inheritance because that's
            > usually the first thing they learn, and once they get the hang of it, they
            > won't let go.
            >
            > André næss[/color]

            Comment

            • Tony Marston

              #7
              Re: What is/is not considered to be good OO programming

              "Philipp Lenssen" <info@outer-court.com> wrote in message news:<bqn8cf$23 206g$1@ID-203055.news.uni-berlin.de>...[color=blue]
              > André Næss wrote:
              >[color=green]
              > > Tony Marston:
              > >[/color]
              >[color=green][color=darkred]
              > > >
              > > > I have condensed the arguments into a single article which can be
              > > > viewed at
              > > > http://www.tonymarston.net/php-mysql/good-bad-oop.html
              > > >[/color][/color]
              >[color=green]
              > >
              > > I just think it's funny that you still don't understand object
              > > composition. In your article you write: "How do you share code in OO
              > > systems? Through inheritance.", not even mentioning object
              > > composition. Object composition was also the crux of my argument,
              > > i.e.: where you see only inheritance, I see inheritance and
              > > composition. From this we can only deduce that you in fact did not
              > > properly understand my argument. That doesn't make the discussion any
              > > easier.
              > >[/color]
              >
              > I was thinking the same. I saw the article, looked for "compositio n",
              > couldn't find it, and went away.[/color]

              Just for you I have added a section on object composition. I hope you like it.



              Kiss, kiss

              Tony Marston
              This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

              Comment

              • André Næss

                #8
                Re: What is/is not considered to be good OO programming

                Tony Marston:
                [color=blue][color=green]
                >> Object composition
                >> was also the crux of my argument, i.e.: where you see only inheritance, I
                >> see inheritance and composition. From this we can only deduce that you in
                >> fact did not properly understand my argument.[/color]
                >
                > You argument is irrelevant as it serves no useful purpose when
                > discussing a single abstract class.[/color]

                I wasn't discussing a single abstract class. I was discussing a solution to
                a problem. The single abstract class and proliferation of new classes is
                *your* solution. I tried to argue that a different, and IMO better approach
                was possible. You didn't bother to learn about object composition until
                *now*, yet you disagreed with my idea of using it in your case. In other
                words, you had decided that your solution *is* the best even before you
                started the discussion, despite the fact that you did not know much about
                OO.

                André Næss

                Comment

                • Doug Hutcheson

                  #9
                  Re: What is/is not considered to be good OO programming

                  "Tony Marston" <tony@marston-home.demon.co.u k> wrote in message
                  news:7588a50f.0 312050544.1dad5 b57@posting.goo gle.com...[color=blue]
                  > "Philipp Lenssen" <info@outer-court.com> wrote in message[/color]
                  news:<bqn8cf$23 206g$1@ID-203055.news.uni-berlin.de>...[color=blue][color=green]
                  > > André Næss wrote:
                  > >[color=darkred]
                  > > > Tony Marston:
                  > > >[/color]
                  > >[color=darkred]
                  > > > >
                  > > > > I have condensed the arguments into a single article which can be
                  > > > > viewed at
                  > > > > http://www.tonymarston.net/php-mysql/good-bad-oop.html
                  > > > >[/color]
                  > >[color=darkred]
                  > > >
                  > > > I just think it's funny that you still don't understand object
                  > > > composition. In your article you write: "How do you share code in OO
                  > > > systems? Through inheritance.", not even mentioning object
                  > > > composition. Object composition was also the crux of my argument,
                  > > > i.e.: where you see only inheritance, I see inheritance and
                  > > > composition. From this we can only deduce that you in fact did not
                  > > > properly understand my argument. That doesn't make the discussion any
                  > > > easier.
                  > > >[/color]
                  > >
                  > > I was thinking the same. I saw the article, looked for "compositio n",
                  > > couldn't find it, and went away.[/color]
                  >
                  > Just for you I have added a section on object composition. I hope you like[/color]
                  it.[color=blue]
                  >
                  > http://www.tonymarston.net/php-mysql...tml#2003-12-05
                  >
                  > Kiss, kiss
                  >
                  > Tony Marston
                  > http://www.tonymarston.net/[/color]

                  Tony,
                  A trifle defensive <grin>, but wholly correct. As another 25+ programmer, I
                  can state without too much fear of contradiction that the customer pays me
                  to solve his problem, not to write code which meets the approval of the
                  paradigm police.
                  More power to you, you rabid radical you!
                  Cheers,
                  Doug Hutcheson


                  Comment

                  • Matty

                    #10
                    Re: What is/is not considered to be good OO programming

                    Doug Hutcheson wrote:
                    [color=blue]
                    > "Tony Marston" <tony@marston-home.demon.co.u k> wrote in message
                    > news:7588a50f.0 312050544.1dad5 b57@posting.goo gle.com...[/color]

                    <snip>
                    [color=blue][color=green]
                    >>
                    >> http://www.tonymarston.net/php-mysql...tml#2003-12-05
                    >>[/color][/color]

                    <snip>
                    [color=blue]
                    > Tony,
                    > A trifle defensive <grin>, but wholly correct. As another 25+ programmer,
                    > I can state without too much fear of contradiction that the customer pays
                    > me to solve his problem, not to write code which meets the approval of the
                    > paradigm police.
                    > More power to you, you rabid radical you!
                    > Cheers,
                    > Doug Hutcheson[/color]

                    Wow, it's come back to life again!

                    Asbestos manufacturers everywhere must be looking forwards
                    to this one!

                    ;p

                    Matt

                    Comment

                    • Matty

                      #11
                      Re: What is/is not considered to be good OO programming

                      Matty wrote:

                      [color=blue]
                      > Wow, it's come back to life again!
                      >
                      > Asbestos manufacturers everywhere must be looking forwards
                      > to this one!
                      >
                      > ;p
                      >
                      > Matt[/color]

                      FWIW, I still think it's better to have 12 different instances,
                      rather than 12 different classes <duck />... Not read it all yet,
                      just a quick search! I'll have a good read through tomorrow, but
                      I do think there aren't sufficient differences between tables in a
                      database to justify having a separate class to handle each table,
                      when a separate instance of a suitably generic class would handle it
                      OK.

                      I am definitely a TMTOWTDI kind of person, though, and I do agree
                      that fundamentally, if the software works, then it's good.

                      Matt

                      Comment

                      • Matty

                        #12
                        Re: What is/is not considered to be good OO programming

                        >> "Tony Marston" <tony@marston-home.demon.co.u k> wrote in message[color=blue][color=green]
                        >> news:7588a50f.0 312050544.1dad5 b57@posting.goo gle.com...[/color]
                        >
                        > <snip>
                        >[color=green][color=darkred]
                        >>>
                        >>> http://www.tonymarston.net/php-mysql...tml#2003-12-05
                        >>>[/color][/color][/color]

                        (Yet Another Follow Up...)

                        Can't help wondering what the object composition argument was, and how
                        on earth you could do it in a logical manner.

                        A table "has a" page of records?

                        A page of records "has a" table (what would it do if it didn't?)

                        Personally, yeah, I think composition isn't the way to do it...

                        /me thinks How about a table "has a" table perhaps???


                        ;p

                        Matt

                        Comment

                        • Tony Marston

                          #13
                          Re: What is/is not considered to be good OO programming

                          André Næss <andrena.spamre allysucks@ifi.u io.no> wrote in message news:<bqq53c$c6 9$1@maud.ifi.ui o.no>...[color=blue]
                          > Tony Marston:
                          >[color=green][color=darkred]
                          > >> Object composition
                          > >> was also the crux of my argument, i.e.: where you see only inheritance, I
                          > >> see inheritance and composition. From this we can only deduce that you in
                          > >> fact did not properly understand my argument.[/color]
                          > >
                          > > You argument is irrelevant as it serves no useful purpose when
                          > > discussing a single abstract class.[/color]
                          >
                          > I wasn't discussing a single abstract class. I was discussing a solution to
                          > a problem. The single abstract class and proliferation of new classes is
                          > *your* solution. I tried to argue that a different, and IMO better approach
                          > was possible.[/color]

                          It may seem better in your opinion, but to my mind it is different
                          without any obvious benefits, so there is no point in changing.
                          [color=blue]
                          > You didn't bother to learn about object composition until
                          > *now*, yet you disagreed with my idea of using it in your case.[/color]

                          Object composition is not listed among the principles of OOP, so I
                          ignored it. When I did read about it the first thing that I saw was
                          that it was considered as an alternative method of dealing with
                          complex hierarchies. As I do not have a complex hierarchy (just two
                          levels) there seems no point in investigating it any further.
                          [color=blue]
                          > In other
                          > words, you had decided that your solution *is* the best even before you
                          > started the discussion,[/color]

                          I never said it was the best, I merely said that it is simple and it
                          works. As a follower of the KISS principle this is VERY important. Why
                          waste time on a complex solution if a simple one works?
                          [color=blue]
                          > despite the fact that you did not know much about OO.
                          >
                          > André Næss[/color]

                          It is true that I have not been taught any OO, but that means that I
                          have not been taught the wrong things. What I have read about OO tells
                          me that objects are not that much different to components, and as I
                          have been working with a component-based development language for the
                          last 10 years all I did was to take my component-based design and
                          convert it to object-based. Simple and effective.

                          The fact that I do not do OOP in the way that you do it is irrelevant.
                          I can achieve rapid results my way, so my way is good for me (and a
                          few others according to the emails I have received).

                          Tony Marston
                          This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                          Comment

                          • Philipp Lenssen

                            #14
                            Re: What is/is not considered to be good OO programming

                            Tony Marston wrote:
                            [color=blue]
                            > "Philipp Lenssen" <info@outer-court.com> wrote in message
                            > news:<bqn8cf$23 206g$1@ID-203055.news.uni-berlin.de>...[color=green]
                            > > André Næss wrote:
                            > >[/color][/color]
                            [color=blue][color=green]
                            > >
                            > > I was thinking the same. I saw the article, looked for
                            > > "compositio n", couldn't find it, and went away.[/color]
                            >
                            > Just for you I have added a section on object composition. I hope you
                            > like it.
                            >
                            > http://www.tonymarston.net/php-mysql...tml#2003-12-05
                            >[/color]

                            You should differentiate between "has a" and "is a". I believe I
                            recently posted this here and the idea is neither mine nor new.

                            Inheritance examples in books often go by the examples of employees.
                            And employee "is a type of" person. So it would not make sense to use
                            object composition. (Not if person and employee are intended to be the
                            same anyway.) Because an employee shares attributes of a person but
                            includes his own.

                            Now let's say I have a class "webpage". Now this "webpage" has a
                            complex module "binary_ima ge" which will render images. You would use
                            simple object composition by creating a new instance of "binary_ima ge"
                            within "webpage".

                            Why is it composited and not inherited?
                            Because the webpage "has a" binary image. However, it's wrong to say
                            binary_image "is a type of" webpage. 'Cause it's not.

                            This was just an example. Usually I don't use global instances of
                            objects either in a class. Usually they just go right into the
                            function. E.g. using the file-system object from within a class on a
                            Windows server. Or handling XML.

                            And object composition structures the code and can make it more
                            readable. It's often more natural. But whatever approach suits you.
                            Don't forget however that if you're working in a team you can't just
                            say "my approach is better 'cause I like it and everyone should code
                            the way they want", because code must be managed by others. You
                            wouldn't expect your code to be rewritting from scratch or highly
                            refactored if you were sick for a week and someone else had to go
                            through it. So you should write code in ways accepted and used in your
                            team, and to find the best solution you must argue beyond personal
                            taste. Sometimes, you may even need to compromise.

                            Comment

                            • Tony Marston

                              #15
                              Re: What is/is not considered to be good OO programming

                              "Doug Hutcheson" <doug.nospam.hu tcheson@nrm.qld .gov.au> wrote in message news:<B%NAb.104 2$hX1.34374@new s.optus.net.au> ...[color=blue]
                              > "Tony Marston" <tony@marston-home.demon.co.u k> wrote in message
                              > news:7588a50f.0 312050544.1dad5 b57@posting.goo gle.com...[color=green]
                              > > "Philipp Lenssen" <info@outer-court.com> wrote in message[/color]
                              > news:<bqn8cf$23 206g$1@ID-203055.news.uni-berlin.de>...[color=green][color=darkred]
                              > > > André Næss wrote:
                              > > >
                              > > > > Tony Marston:
                              > > > >[/color][/color]
                              >[color=green][color=darkred]
                              > > > > >
                              > > > > > I have condensed the arguments into a single article which can be
                              > > > > > viewed at
                              > > > > > http://www.tonymarston.net/php-mysql/good-bad-oop.html
                              > > > > >[/color][/color]
                              >[color=green][color=darkred]
                              > > > >
                              > > > > I just think it's funny that you still don't understand object
                              > > > > composition. In your article you write: "How do you share code in OO
                              > > > > systems? Through inheritance.", not even mentioning object
                              > > > > composition. Object composition was also the crux of my argument,
                              > > > > i.e.: where you see only inheritance, I see inheritance and
                              > > > > composition. From this we can only deduce that you in fact did not
                              > > > > properly understand my argument. That doesn't make the discussion any
                              > > > > easier.
                              > > > >
                              > > >
                              > > > I was thinking the same. I saw the article, looked for "compositio n",
                              > > > couldn't find it, and went away.[/color]
                              > >
                              > > Just for you I have added a section on object composition. I hope you like[/color]
                              > it.[color=green]
                              > >
                              > > http://www.tonymarston.net/php-mysql...tml#2003-12-05
                              > >
                              > > Kiss, kiss
                              > >
                              > > Tony Marston
                              > > http://www.tonymarston.net/[/color]
                              >
                              > Tony,
                              > A trifle defensive <grin>, but wholly correct. As another 25+ programmer, I
                              > can state without too much fear of contradiction that the customer pays me
                              > to solve his problem, not to write code which meets the approval of the
                              > paradigm police.
                              > More power to you, you rabid radical you!
                              > Cheers,
                              > Doug Hutcheson[/color]

                              People tend to describe me more as revolting than rebelling. Is there
                              a difference? :)

                              Tony Marston
                              This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL

                              Comment

                              Working...