Hoy Crap! Java is self-referential.

So I’m making a class (object*). Let’s call it Cadobj. I’m writing a method in Cadobj and I’m thinking that I’d love to pass the entire variable that is an instance of Cadobj to the method. Obviously I can’t do that because using a variable of type Cadobj in Cadobj itself is like a Klein bottle of programming (or would that be Quine bottle?). But I figure what the hell and the damn thing works. I’m not sure why I’m impressed but I am. I don’t even know if I should be impressed with myself for being so clever or impressed with Java for letting me do it.
*if it is an object, why do we call it a class? Back in the 90’s I spent 2 frustrating weeks trying to teach myself OOP on Turbo Pascal and gave up because I could never find the OBJECT type declaration. It wasn’t until I started learning Java that I realize class=object; but it’s still stupid we program it using “class” and not “object”.

Don’t all languages allow that?

A ‘class’ is a type. An ‘object’ is a member of the type. In other words, an object is an instance. Like Aristotle’s classification system.

You can find the beginnings of this even in the earliest versions of the plain-old-C language.

It was allowed to define structures containing members that were pointers to other structures that hadn’t been defined yet, or pointers to the same kind of struct itself. The language went out of its way to explicitly allow this, just for this purpose.

Thus, it was possible to define two structs, A and B, each of which could contain a pointer to the other. Or a struct definition could contain a pointer to itself. (Meaning, a pointer to a struct of the same type as itself.)

You know what, I had an idea I could do that so like I said I don’t know why I’m so impressed with it. Maybe I’m impressed that it only took me 3 days of being an idiot before thinking about it as a solution.

There are quite a few methods that use this ability to create very elegant solutions in many languages. But, the idea does seems rather odd when you aren’t immersed in the computer language itself. The fact that an object can contain itself (or more properly another instantiation of itself) seems absurd, but there you have it. Obviously there are limits to the levels of recursion allowed, if only in the memory allocation.

The name Object Oriented Programming was a mistake. It should have been called Class Oriented Programming. This confuses many people. A Class is a general definition, and an Object is a specific thing that is defined by a Class. It’s the difference between ‘cars’ in general, and your ‘car’.

There is a distinction between class and object that is muddled by design choices of the Java programming language. Historically, the term class referred to the definition of a set of properties & behavior, and the term object referred to an instantiation in memory of a widget that had those properties and exhibited that behavior.

Java has two classes that muddle this distinction. Muddled because those classes are named Object and Class (actually, the latter is a generic, but I’m simplifying a bit). Make no mistake, the class Object is indeed a class. And if you have an object of type Object and call object.getClass() you will get an object. The object will be an instantiation of the class Class, but it’s still an object.

You know where babies come from, right?