Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

OO Inheritance

Name: Anonymous 2011-08-19 23:20

Object Oriented Programming Inheritance. Is there even a point to it? Every time I see people try to explain it they always use that fucking "Animal", "Dog", "Cat" example. I'm honestly not seeing the benefits here. Can someone give me a practical example?

Name: Anonymous 2011-08-19 23:32

Part of it is to do with sharing code. In C# for example, you have System.IO.StreamReader for streaming input from files and System.IO.StreamWriter for streaming output to files (they aren't the only classes for file IO but bear with me). If you wanted to combine the two, to make a StreamJesus class you would use inheritance. Unfortunately in C# there's no (direct) way  to inherit two classes*, but you get the point.

* You can get around it, see: http://stackoverflow.com/questions/178333/multiple-inheritance-in-c

Name: Anonymous 2011-08-19 23:41

Inheritance is the most overused feature of OO, most C++/Java/C# books teach inheritance as a way to organize code as though you should use it at every possible chance. But the fact is that inheritance is very confining and can bring about a needless explosion of subclassing. This is why Design Patterns were developed, so programmers can unlearn inheritance and use nodal style of OO where classes are interconnected nodes.

Name: Anonymous 2011-08-20 0:17

Object Oriented Programming considered harmful

Name: Anonymous 2011-08-20 0:43

OOPs

Name: Anonymous 2011-08-20 3:13

Google SICP

Name: Anonymous 2011-08-20 4:01

>>6

why does google say that mitpress.mit.edu/sicp/ is "THE SICP Website"? I thought it was /prog/

Name: Anonymous 2011-08-20 4:09

If you have read SICP, object inheritance is partially discussed at the end of chapter 2- although it's not explicitly called inheritance.

We wish to have a generic arithmetic package, so we can not only add or subtract with different types (polynomials, rationals, integers..) but compose them, for example to get polynomials with rational coefficients.

This is achieved almost effortlessly through use of data directed programming, and what we are really doing in OO terms, is constructing an inheritance tree; where each of the primitive types (polynomials, rationals, etc..) implements a base generic type (not explicitly named in SICP, although it's analogous to the apply-generic function).

I won't explain it further because you can go and read SICP yourself- if not you should probably reconsider your career.

Name: Anonymous 2011-08-20 4:12

i have likewise come to the conclusion that classic inheritance is mostly awful...

lately i have been interested in "traits", a way of composing behaviour without having to have one specific ancestor:

http://scg.unibe.ch/archive/phd/schaerli-phd.pdf

i'm not certain yet, but it seems like a more useful way of structuring things.

Name: Anonymous 2011-08-20 4:55

SICP is for lisp faggots

Name: Anonymous 2011-08-20 10:50

>>9
Interfaces?

Name: Anonymous 2011-08-20 13:29

Evaluating the thoughts of mine would apply a lewd multimethod to ourselves, if you read what I print.

Name: Anonymous 2011-08-20 15:45

    <?php
   
    class DatabaseManager
    {
        public function getConnection ( )
        {
            return new mysqli('localhost', 'root', 'root', 'example');
        }
    }
    
    class UserInteraction extends DatabaseManager
    {
        private $userInformation;
       
            public function __construct ( )
        {
            $sql  = $this->getConnection();
            $stmt = $sql->query("SELECT * FROM ... LIMIT 1");
           
                if ( $stmt->num_rows > 0 )
            {
                $this->userInformation = $stmt->fetch_assoc();
            }
        }
     }

Derp herp

Name: Anonymous 2011-08-20 15:48

Inheritance is great for things like GUIs. If you ever written a desktop application, the benefit will be obvious.

Name: Anonymous 2011-08-20 18:38

I wrote a program which intercepted packets in real time, and since all packets share common traits, the classes for incoming and outgoing packets were derived from a common packet class.

Name: Anonymous 2011-08-20 18:41

>>15
I forgot to mention: it was only useful because I could store all packets in one container.

Name: Anonymous 2011-08-20 19:04

inheritance is used in C++ for code sharing and static interface assurance, which actually are two very different things that shouldn't be confused.

Name: Anonymous 2011-08-21 1:53

>>14
That's funny, because I've found that the dark side of inheritance is most obvious when trying to write a GUI. Teetering your way through some kind of stubbornly linear widget phylum is not just aggravating, but a blatant case of hammering a screw.

Name: Anonymous 2011-08-21 2:39

Name: Anonymous 2011-08-21 6:05

how about screwing a hammer

Name: Anonymous 2011-08-21 16:11

>>19,20
How about you kill yourselves

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List