Results 1 to 2 of 2
  1. #1
    Stropert is offline Member
    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Default Main parent object

    I've seen in a few projects already (vlc, Qt, all object oriented languages, etc) that have a main object, i.e. java has Object, Qt has QObject, Python has Object, libVLC has vlc_object_t, and so on.

    So my question is, is it good practice (design pattern) to do stuff like this? If I develop some kind of library/framework, should I do the same?
    Why is it actually done that way?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Main parent object

    Many languages which advertise themselves as "object oriented" organise their type system around the notion of a class. (So they might better be described as "class oriented") By "type" I mean the sort of thing that an object is: the sort of behaviour and state that it has.

    And there is usually some notion of "inheritance" whereby some type (class) is defined as also having all the behaviour and state of some other class (its parent). In Java classes have just one parent, or immediate superclass. Tracing this notion of inheritance back from a given class it is good to have a "stopping point" so that it is well defined just what behaviour and state that class is inheriting. I don't think it is necessary but most languages of this sort trace the ancestry of any given class back to a common ancestor shared by all classes. This allows all classes to share some common behaviour that the programmer can rely on (like the toString() method in Java), and, by convention, it is called Object.

    This is not the sort of "pattern" that the programmer need worry about (or attempt to emulate): it's just a given for languages of this sort.

    Also it's not a universal feature of object orientedness. In JavaScript, for instance, an object - not a class, but a specific instance - inherits its behaviour and state from some other object. "Class oriented" languages as I've described them allow for strong typing: the compiler knows, even before the program is run, what sort of methods are able to be legally called on a variable declared to belong to some specific class. "Prototypical" languages like JavaScript forsake this type checking in favour of more flexibility of objects, at runtime, to do whatever is appropriate at the moment the program is being run.

Similar Threads

  1. Replies: 3
    Last Post: 08-25-2011, 08:57 AM
  2. Main Method Can't Find It's Parent Class
    By Slinkie45 in forum New To Java
    Replies: 11
    Last Post: 05-09-2011, 02:37 AM
  3. Replies: 1
    Last Post: 01-23-2011, 05:19 PM
  4. substract Parent class object from child class
    By nikosv in forum New To Java
    Replies: 0
    Last Post: 12-08-2010, 12:30 AM
  5. Replies: 1
    Last Post: 03-04-2009, 06:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •