Slimelite BBS

VB/TBV/VBC++ (was Cop

Back to DRIVING

From David Jones · 1996-04-09 07:35 · #69281 in DRIVING

Noticed Peter Dalton's message to David Jones about VB/TBV/VBC++ (was Cop 

 
 DJ> OO matters for a whole host of reasons. Reliability and stability of
 DJ> code (after all, your components or base classes will already be out

 PD> could you take a few minutes to explain what 'OO' is please. I see the
 PD> references all over the place...

   Deep breath...

   Really, though, it's not that complicated. Once you're into it, you
   wonder how you ever thought any other way...

   OO : Object Orientation. First came to fruition in the early 70s
   through SmallTalk, an OO language which some purists (except
   enthusiasts for Eiffel) measure every other OO language against.

   You can be strict about it or you can be pragmatic. The most
   commonly used OO language, C++, veers towards pragmatism rather than
   idealism.

   The basic idea is that the language has /structures/ which support
   the notion of closely coupling data with the functions that operate
   upon that data. So a 'window', say, may have data members which
   describe position, colour, title etc; and it may have functions
   which allow you to move it around, to hide it, to minimise it.

   Sounds ok so far?

   Right, well the next step is /inheritance/.  You may have an object
   that describes (encapsulates being the OO terminology) a clickable
   button. But you might want a button that looks a bit different -
   perhaps has a different colour (to be trivial, and this isn't what
   you'd actually do with inheritance but more later...). Now instead
   of cutting and pasting /all/ the description of this object and
   /all/ the functions, you simply say, "I'd like something that's
   descended from that button - oh but make it blue". And the only bit
   you'd have to write is the bit that makes it blue...you've inherited
   all the other stuff from the parent button, so it knows to go down
   when you click on it with a mouse, for example, even though you
   don't tell it to...the behaviour's /inherited/ from the parent
   description. 

   Then there's /polymorphism/. Simply, it means that your inherited
   object can redefine some of the functions and yet still work
   properly. You might have a function in your parent (or 'base') class
   which needs to be a bit different in its operation for an inherited
   class; or maybe it needs to be completely different. If your base
   class has been well designed you'll be able to /override/ the
   function and provide new code. For example :

   Imagine you have a general base class called 'Shape'. This might
   well be what's called an /abstract/ class - you don't actually ever
   want to have just a 'shape' in your program; rather, you want
   particular shapes like a square or a circle. But into your base
   class you put all the data and and the functions that all shapes
   have in common. Now every shape will need to /draw/ itself, so in
   your base class you include a function (a 'method') called 'Draw'.
   It doesn't have to /do/ anything. As long as you follow the syntax
   of the particular OO language you're writing in (for example, in C++
   you call the method 'virtual') you'll be able to provide the
   particular functions that draw a circle or draw a square in your
   derived classes - and any function in your base class, Shape, which
   uses the 'Draw' method will call the appropriate method in the
   derived class.

   And finally there's encapsulation, which basically means that you
   don't let other classes or functions have access to class data or
   class methods unless there's a very good reason. In C++, for
   example, methods and data can be private (usable only by the class
   itself) or protected (usable by the class and its descendants) or
   public (usable by anyone). As a general rule of thumb you will
   provide access to class data only through methods.

   Hope that's not too unclear. It's a bit brief, though. I've found
   that a good understanding will come through using OO languages (and
   the plural is intended - a comparison between languages is very
   illuminating).

--- WILDMAIL!/WC v4.12 
 * Origin: Ooh! BBS, London [MULTILINES]  0181-395-3108  (2:254/233.0)