Global monsters

But you already use classes every day, all day long. Classes are general descriptions. Houses, Rooms, Cars, Tables, Clothes, Transportation, Reports, Appointments, etc are all classes. When I talk about “cars pollute the air” then you know what I’m talking about. When I say “Your car needs a wash” then I talk about a specific object instance of the class Cars.

When you talk about dogs and cats then

  • dogs is a class, “Golden Retriever” is a class, with “Buddy” being a specific object instance of it
  • cats is a class, “Siamese Cats” is a class, “Kitty” is a specific object instance of it.

It is much easier and far less error prone to pass around objects that encapsulate properties

Wife.gets( “Kitty” )

than pass all the details, like

Wife.gets( name, head, tail, body, leg1, leg2, leg3, leg4, furcolour, … )

By using an object you keep all the properties, methods, events etc together.

Btw I came from a procedural background (first contact with programming in 1980 on a ZX81, then a Commodore C64 in 1985), and getting my head around object-oriented programming was the hardest step for me.

My blocks startet with something very simple: a person for me was a subject, not an object. It took the realization that computers don’t know the difference, for them EVERYTHING is an object.

The next realization was that EVERYTHING really means EVERYTHING. In normal language use an object is something you can touch, but again a computer has no idea. It doesn’t have eyes, so it is all the same for it, whether it’s a car or an appointment.

A class is simply a description of an object, what properties it has, what events it reacts to, what methods it implements. It is a blueprint on how to make object instances. So if you tell the computer

Dim myCar as new Car

then the computer knows how to construct myCar by looking at the class Car, and you can then set the properties of the instance according to what you defined in the class. If your class has a property

Owner as String

then you can set its owner with

myCar.Owner = “Mark Jordan”

For your wife you create a second instance:

Dim myWifesCar as new Car myWifesCar.Owner = “Cathy Jordan”

Note that if you only have ONE car then you might write

Dim myWifesCar as new Car myWifesCar = myCar

Now BOTH instances myCar and myWifesCar point to the same object. There are no two cars, there are just two instances myCar and myWifesCar pointing to the same car aka object.

If you now write

MsgBox myWifesCar.Owner MsgBox myCar.Owner

then you’ll get “Mark Jordan” twice.

Thanks for the great illustration/example. You a teacher by any chance?

Classes are becoming clearer to me. I’m rewriting some code to change former global variables into a class unit. It’s coming along … slowly. (Those darn global variables have tentacles that reach everywhere into program).

In my mind globals are sort of evil.
They block your design from re-use and re-instantiation of a member of the same class…
It’s about scalability of design. Encapsulate all those methods and variables into a class and then you should be enlightened as to why…

A good friend of mine who was trying to teach me OO said take that big hunk of code and sort the use of each variable by each method. (function) then group the variables and functions that go together together in a class definition.

Gone are the days.

000140 DATA DIVISION. 
000150 WORKING-STORAGE SECTION. 
000160 01 DATA-01 PIC X(2) VALUE SPACES.

Molecular Biologist. But I have a knack for teaching (as many have told me), and always thought I would become a teacher some day. Seems I waited too long as they have an age limit for becoming a school teacher … but maybe I’ll go into adult education …

I’m a retired teacher. In Indiana a molecular biologist of any age would likely be welcomed to the teaching staff. Our state made provisions for non-education majors to cut through some of the red tape. A guy I taught with started out in public schools (math), quit because he “failed” as he put it, went into the private sector, made a bunch of money, and at age 55 came back as a teacher at much, much lower pay … because he wanted to prove to himself that he could. And he did.

We have the same here in Germany. However some years ago they had a big reform of the forestry services, and 5,000 foresters were no longer needed. As they were “Beamte” they could not get dismissed and were instead put into secondary schools as … Biology teachers. So the one subject that does not require me to fulfill all the requirements and study from scratch is the one that doesn’t need me.