Is OOP actually useful? (1 Viewer)

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
Since I just posted something about this, I want to ask other people here:

Does OOP actually need to exist? I have not yet read the wiki article on OOP but I will at some point. I personally don't see a need for it, and I kind of suspect it gained popularity because the creators marketed it as an "easier" way to program via separating different parts of code based on purpose. Perhaps programmers also think it is easy to debug and document?

I have no idea.
 

Ranman256

Well-known member
Local time
Today, 18:20
Joined
Apr 9, 2015
Messages
4,337
people want to point & click.
nobody wants the old days of typing out command lines.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
people want to point & click.
nobody wants the old days of typing out command lines.
Is the "point and click" concept even related to OOP? Aren't there plenty of old languages that offer "point and click" user interfaces that are not technically OOP languages?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:20
Joined
Feb 28, 2001
Messages
27,172
OOP is a different way of looking at things. Let's see if I can give you a perspective. And since my first programming was done in FORTRAN II-D on an old IBM 1620 mod II in the 1960s, I can talk about OOP from that time.

Programming started out by making humongous arrays. The typical approach was a set of parallel arrays. By that I mean that each thing we would call a property was the name of an array. So the first object's name was in the OName(1) slot. Its color was in the OColor(1) slot. This meant you had as many arrays as the properties you were tracking. Not really that difficult to wrap your head around.

But there was this new thing called "structures" where instead of parallel arrays of properties, you created a single array of a complex structure. So that meant that Object(1) had elements of name, color, weight, etc. To the computer it made no difference because the compilers could keep track of that stuff for you either way you looked at it.

As procedural languages evolved, though, people started thinking about how long it took to write the code to set up these arrays of objects or these parallel arrays, either way you cut it. As it became clearer conceptually that computers were the ultimate model-makers, the idea of making an object out of a structure started to develop. And the issue is that if you had an object, you could do things with it. Including build code called "constructors" and "destructors" to create or destroy objects, to initialize and close them down, whatever they were doing. And that started the idea of having CODE be built into the object.

Think for a moment about Windows. You can still do this today. Pick an icon on the screen. That icon is there because the object underneath it identifies that icon. (You can click "Properties" and get to something that would let you change the icon.) If you right-click on the object, you get a list of things you can do with that object. You can open it (assuming it is openable). You can rename it, delete it, copy it, cut it, paste it, change its properties such as security, ownership, etc.

If you consider the old way of doing things, what we do now is define CLASSES of objects for which certain actions are possible for ALL MEMBERS of that class. We don't have to individually program the list of actions for each object. It is enough that it is a member of a class such as files in order to know a lot of things that can happen.

But the next step is sub-classes. In Windows, this is what is called an association. All files have basic file manipulation. But some files have more things that they can do based on the programs that work with those particular files. So files of type .DOC, .DOCX, and a few others can be opened by WORD. Files of type .XLS, .XLSX, .CSV, and a few others can be opened by EXCEL. And so on. And you don't have to do anything but get the file type correct in order for the correct sub-class options to be added to that list of things you can do with a file.

That is because a file, being a member of a particular class of objects, has a predetermined set of things you can do with it (in Access, called "methods.") This is what OOP gets you.

At the device-driver level, though, OOP is still playing around, even though sometimes you are below the level of files. For instance, a serial port can do input and output. You can open a serial port as though it were a file. Same for parallel ports. Same for networking ports. The drivers for the devices will take any request but sometimes the result is a no-op (null operation). For instance, you can open a serial port but a directory operation will only return the device name. You can close a serial port but no file actually gets stored because of that. The point, though, is that except for certain specialized scientific devices, ALL device drivers treat ALL devices like objects that can do I/O.

This is getting far afield, but I have one more point to make: The mindset of OOP is that you are modeling something. What you put inside the model might make it a black box to the world that uses it, but the object's programmer-creator is simply defining what you can do with it (and equally, what you can't.)

We could get really deep into the weeds by discussing inheritance, because sub-classes inherit properties and methods from their base class, but perhaps you might need to do some reading or thinking first before deciding that OOP is not needed.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
That was very descriptive my friend! Im going to send ur post on to a recruiter that once asked me to explain object oriented programming to him. I didnt say as much as i could have but i did explain the "properties" concept to him. I didnt get into inheritence but the idea of "parents" and "children" in programming im sure can be easily understood by non technical people. What do u have to say on the subject of inheritence? I would be interested in ur take on that.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:20
Joined
Feb 28, 2001
Messages
27,172
Inheritance is the next logical step if you take the "building blocks" viewpoint of program design. Rather than make every scaffold anew every time for every structure, build on what you have, sort of like having "extra tools in the toolkit."

Back to the FILE class for discussion and examples: An every day, run-of-the-mill file can be launched if it is an executable, or its associated utility image can be launched against it if it is a document, picture, music track, or movie. But let's look at that more closely. Let's see what happens if we have an association. Remember that I said it was similar to declaring a sub-class of file that is subject to the named association of utility to file type.

Go find a NOTEPAD file (or make one.) Right-click on it and see what that list of possible actions looks like. Now find a directory file. Again, right-click and look at the actions. Find a picture file, do the same thing.

What you will see in each case are things that you can do to or with the file. Some of those things come from the utilities that can open it. Some come from the simple fact that it is a file. One can argue that the sub-class is a totally new class because of the new things you can do with it. Probably not wrong. But the things that can be done in common among the text file, picture file, and directory file are INHERITED from the general "file" class. Things like cut/paste, copy/paste, delete, change protection, change ownership, rename, ... these are abilities of the base class FILE. Things like name, size, date of creation, date of last modification, ... these are properties of the base class as well.

However, if you look at the details of the picture file, you might find the dimensions of the image (in pixels). You might find info about the color map. These are new properties unique to the sub-class, properties that were NOT inherited but rather were added when you defined the new sub-class.

If you look at executable images (.EXE) you would find that they have "Run As..." options and "compatibility-mode" options. If you look at file folders (.DIR), you would find compression and indexing options. Again, these represent actions or properties of the sub-class associated with that file type.

As it happens, you can do this to a limited degree in Access VBA. You can create a type of control that is a sub-class of another control. It will do all of the things that its base class control can do, but it can be made to do more. The problem is, of course, making sure that you don't botch/interfere with the "normal" properties and methods of the base class object. But you have the world of imagination at your fingertips if you are willing to devote yourself to a project that requires meticulous attention to detail for at least a brief time.

Inheritance, done properly, is a much faster way to "spiffy up" a project. Done poorly, it will make you prematurely have to join the Hair Club for Men after you have yanked out the hair you thought you had.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
Doc Man,

Do you have any experience with current OOP languages like Java, C#, Python or C++? Sometimes I think the "levels" that are used with OOP are a great way to organize a code project and avoid the "pulling your own hair out" scenario. For instance, the namespace, the class, the method, etc...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:20
Joined
Feb 28, 2001
Messages
27,172
To be honest, my knowledge is mostly theoretical.

When I went through college, OOP was just becoming a possible thing. I remember having a discussion with a friend who was asking the same questions (more or less) as you have.

There is absolutely no doubt that you can program a project without OOP and for my dissertation research, the little program I built couldn't use OOP. It was all assembly language and in a space-limited environment.

If there is any problem with OOP, the encapsulation makes it hard to fit when you are already shoe-horning code to make things fit. And my main problem was that because of the limited memory, every line of code was one less data point I could take.

I had no disk on that lab computer. Back then, it was all based on paper-tape and something called a RIM loader. There was no swapping or paging. There was no saving to disk.

Therefore, my problem was loading things to memory as tightly as possible. Subroutines weren't a problem. Encapsulation was, because I couldn't afford any code that I wouldn't be using in that environment.

When I graduated, my first job didn't involve OOP that much. We eventually developed something that used some aspects of OOP by abstracting common elements of the oil and gas pipeline industry for our basic control system. Then we allowed "inheritance" of a sort for any custom sensors that didn't map directly to one of the types of sensors we already supported. But as most of that was written in assembly, OOP wasn't really as much of an issue.

By the time I reached my government contractor position, I was in as an O/S manager and systems analyst. The opportunity wasn't there for too many OOP situations. So while I have tried to keep up my reading, I have not dealt with OOP that much. Now that I am retired, it would be a purely academic exercise and I have other fish to fry.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
well regardless of weather you have experience or not, your insights are certainly helpful to us I'm sure! I know I enjoyed reading them.
 

kevlray

Registered User.
Local time
Today, 15:20
Joined
Apr 5, 2010
Messages
1,046
I used an employer created OOP language many years ago (gaming software). It not very fancy, but it was very helpful in creating multiple instances of an object (you could not not create new objects, every thing was a instance of a particular type of object). Thus you could control each instance of an object independently with very little code.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:20
Joined
May 21, 2018
Messages
8,527
Does OOP actually need to exist?
Being this is an Access forum, I think that question is self answering. 99 percent of everything you do in access is OOP. How would you envision working with forms, reports, controls, recordsets, etc if not OOP. VBA is not a pure OOP language since no inheritance or polymorphism, but it is definitely OOP.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
VBA is not a pure OOP language since no inheritance or polymorphism, but it is definitely OOP.
well i've never considered visual basic legacy versions or any variations of it to be OOP. In VBA there are classes and types and stuff and that might get close, but what i'm referring to specifically is what you have mentioned, such as inheritance, plymorphism and the whole idea of creating the coding objects out of properties. In access, I definitely don't consider vba coding that refers to access GUI objects as OOP programming.

Languages that I'm specifically referring to regarding this OOP thing:

Java
Python
C++
C#
VB.NET
PHP
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:20
Joined
May 21, 2018
Messages
8,527
VBA provides the two main tenets of OOP: encapsulation and abstraction. It does not provide the lesser two of inheritence and polymorphism. To me the first two overshadow the other two.

So let me get this straight. If I build a custom class with public accessors, custom events, and protected class variables in VBA it would not be OOP, but if I build the exact identical class in VB.net then it is OOP?

Maybe look at my code in this thread
https://www.access-programmers.co.uk/forums/showthread.php?t=306791
And see if you think that looks like OOP. If I wrote it in JAVA, c#, .net (I know those) it would sure look the same. Could I write this not OOP? I guess but it would be really hard and really clunky.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
If I build a custom class with public accessors, custom events, and protected class variables in VBA it would not be OOP, but if I build the exact identical class in VB.net then it is OOP?
well prolly not, that's why I said that classes and types in VBA are close to OOP. Maybe I should have said building them is technically classified as OOP. I think that would be a better thing to say.

regarding your attachments in that other thread, the public properties in the class modules you wrote I would say is OOP usage.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:20
Joined
May 21, 2018
Messages
8,527
classes and types in VBA are close to OOP. Maybe I should have said building them is technically classified as OOP.
I got to completely disagree. At the route the difference between OOP and functional/procedural programming is the concepts of objects. Build your own objects or using already built objects makes no difference. If you are working with objects in VBA you are doing OOP. It is a limited language as pointed out (not overloading, no parameterized contructors, no polymorphism, no inheritance), but still is OOP. On the other hand procedural programming is structured top down and has not concept of objects.

Code:
Dim RS as dao.recorset
set RS = currentdb.openrecordset ("someQuery")

I just instantiated an instance of an object. Common Access vba task. Not sure how that is not OOP. In procedural programming there is not even a concept of instantiation.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
Code:
Dim RS as dao.recorset
set RS = currentdb.openrecordset ("someQuery")

I just instantiated an instance of an object. Common Access vba task. Not sure how that is not OOP. In procedural programming there is not even a concept of instantiation.
do you have any formal training in this industry? I don't, so it is possible that my conveyance to you really means what you are saying. Let us just say I suck at explaining myself?

But when it comes to explaining these types of things to non-technical people, I would say I'm an expert. I've had very few complaints over the years. and in most employment situations I've been in, it has usually been me who has been the "go between" person between the coders and the users.

on a side note, most of the programmers I've worked with in real life I don't believe spent a lot of time on internet forums. I've always wondered if people who spend a lot of time doing remote work or helping others through the internet are really just as good in real life. In a similar example, I believe the experts say that if you're good on the phone, chances are you're terrible in real life, and vice versa.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:20
Joined
Feb 28, 2001
Messages
27,172
I think that perhaps a part of the issue is that VBA is only pseudo-compiled into an intermediate code that isn't directly executable. Perhaps the polymorphism doesn't work quite right in an interpreted language.

As to polymorphism, not entirely absent. We can't use it - but NZ() can and does.

NZ( x, "" ) returns a string, but NZ(x, 0 ) returns an integer - an example of the same thing returning two different data types.

Granted, we can't count that NZ(x, 0) returns a specific size of integer because it probably does not. THAT, we owe to VBA and variable promotion within an expression.

A definition of polymorphism:

The word polymorphism is used in various contexts and describes situations in which something occurs in several different forms. In computer science, it describes the concept that objects of different types can be accessed through the same interface.

Taken from: https://stackify.com/oop-concept-polymorphism/

If you go on to read further, you realize that the ability to assign a specific type of object to a generic Object variable is also polymorphism.

Therefore, VBA has polymorphism. We can't implement it - but the DLLs for Access have used it and made the functions (and objects) available to us.

Inheritance IS available, in that it is POSSIBLE (though a P.I.T.A.) to create your own special kind of controls that are based on an ordinary control. The new control will inherit the properties of the old control plus any others you might choose to add. We've had threads on that particular ability.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
Inheritance IS available, in that it is POSSIBLE (though a P.I.T.A.) to create your own special kind of controls that are based on an ordinary control. The new control will inherit the properties of the old control plus any others you might choose to add.
I don't think I follow this Richard. Got an example of this happening? Are you talking about using VBA library references to do this?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:20
Joined
May 21, 2018
Messages
8,527
Inheritance IS available, in that it is POSSIBLE (though a P.I.T.A.) to create your own special kind of controls that are based on an ordinary control.
That is not true. Inheritance is definitely not available. Maybe you could kind of fake it. For example An access.textbox does not inherit from access.control. If that was the case then the subclass would inherit all the properties and methods of the parent. These are two just two separate classes. That is not inheritance.

The NZ function is not an example of polymorphism. It takes a variant parmeter as the return and casts the output based on the input. That is in no way the same.
There is no inheritance and no polymorphism in vba.
 

vba_php

Forum Troll
Local time
Today, 17:20
Joined
Oct 6, 2019
Messages
2,880
hmmm...some disagreements and inconsistencies that does not involve me. makes me feel good!
 

Users who are viewing this thread

Top Bottom