Cracking the Code - All Those Classes!

Somewhere along the line, about when OOP came along, I was diverted into doing other things.  So, I lack the "cultural refinement" that must have come along with it.
I've written programs in C, C++, VBA, C#, and Fortran (of whatever recent vintage) but, I must admit, quit in starting on C# because there were all those class names that had no meaning for me.  I couldn't even debug an example program as a result!

I think I understand the general concepts - so that's not it.
It's the specifics that are elusive.
I've seen the same thing in VBA but seem to have been able to get things done.  It was sort of like "programming by example" as in "copy & paste".

I've researched it a bit but don't seem to find the answer.  So:
What is the key to understanding the Classes, what they're called and what they do, so that one can be relatively productive?  Does this come by osmosis?
It must be something like a dictionary....
Or, if the proper term is other than "Classes", can you enlighten me a bit please?
LVL 27
Fred MarshallPrincipalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peter HutchisonSenior Network Systems SpecialistCommented:
All a Class is an encapsulation (or an enclosure) of variables, functions and subroutines that share a common features.

For example 'class' called 'shapes' would have variables and features that relate to shapes:
Variables: Height, length, width, depth, sides.
Functions: New Shape, Delete shape, Rotate shape, Get_Number_of_Sides, Change shape.

For a 'Person' class you would have variables and features that relate to people.
Variables: Firstname,Lastname, Age, Title, Sex, Status, JobTitle, Address, City, Postcode.
Functions: New Person, Delete Person, Change Person.

Since there can be multiple shapes or people then you have to create an 'instance' of a Class to separate them into separate object. So to create a new instance you can use New and the class name and a list of none, one or more parameters to initialise that instance.
JohnObj = New Person("John", "Smith")
SueObj = New Person("Sue", "Shore")

CircleObj = New Shape("100", "circle")
BoxObj = New Shape("50", "square")
and so on

Classes can share variables and functions with other classes. This uses a feature called inheritance, where a class can have its own variables and functions but also the variables and functions of another class (a parent class). This avoids having to duplicate everything into a new class, you can use existing variables and functions from the parent class.
For example, children can be a person, but since they are too you to need all the features of a person.
e.g. Class Child inherits Person

Hope this helps a bit.
Fabrice LambertFabrice LambertCommented:

In general, I see classes as "Services providers", and shouldn't be confused with "data containers".
All that matter is their behavior (what they do) via their public interface (public member functions). Internal data and details doesn't matter.

As to understand what a given class does, a well designed class should have a self explanatory interface (in other words: meaningfull names), else look up for the documentation.
Same goes with class name, it should be meaningfull.

In fact, internal data and details matter a bit, when you are designing your own classes, but always ask yourself in the process: "What is my class supposed to do ?", "does it make sens ?"
Take the string class (C++) as sample. Adding two string result in a concatenation, that make sens. But substracting two string does not, neither multiplying or dividing.

And while I'm at it, when designing classes, one should stick to the SOLID principles.
More infos on Wikipedia.
Fred MarshallPrincipalAuthor Commented:
OK .. but:
The issue I'm having must seem "obvious" to the experienced folks.  So, it must be that I have a "blind spot".

I'll try again:

Given: that a program has a class being used then how does one figure out what it does or is trying to do?
Given: that a program in development NEEDS something, then how does one find an available class that's intended to do the job?
Where is the dictionary or catalog or ......?
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Fabrice LambertFabrice LambertCommented:
There are no dictionaries, neither catalogs.

Whatever the language is, there are documentation available somewhere, beeing official norms, web sites or books.
And for user defined classes, you first hints are class names and member function names, your second hint is the documentation.

Now on program design, class are modeling concepts, abstract or real (in a racing video game, you'll probably have a car or vehicle class).
Experience in software design help a lot tho.
Dave BaldwinFixer of ProblemsCommented:
Fred, now you know why OOP really means Oops!
Fred MarshallPrincipalAuthor Commented:
OK.  So I turned around and looked at my bookshelf and found:
Microsoft Visual C++
MFC Library Reference
Now, *that's* a dictionary.  
So, I guess it's no wonder that I didn't just absorb it all overnight - and promptly forgot about it.

So I will depart from my original question and ask:
How *real* are these things?
Oh, I know they are real enough but how much use do they get?  A little or a lot?
Or do folks just end up writing their own more often than not?
I'm reminded of Standard Electronic Modules.  Somehow they never quite matched the next need and new designs proliferated.
Fabrice LambertFabrice LambertCommented:
Most languages come with a "Standard Library" with bunch of built-in functions and / or class.
Some or more usefull than other.

For instances, you'll see that you can't live without strings, containers (static / dynamic arrays / collections / lists ), files, smart pointers (mainly in C++) ect ect ...
Some are less usefull and / or situational (network, threads, complex numbers, bit sets, ect ect ...).

But there are always cases where the functionalities offered by standard libraries don't cover your needs (make sens since those libraries tend to be generic), here user defined classes comes into the equation.

Let's say, you want to represent a CSV file, no problem, a simple dynamic 2D array of strings can handle that.
But on the other hand, if you want to represent a mathematical matrix, you'll see that you'll need to provide operations such as adding, substracting and multiply matrixs as these fonctionalities arn't covered by standard libraries.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Fred, I'm in the same position as you with OOP.  It appears to me that writing code that uses OOP and libraries requires more planning.
Fred MarshallPrincipalAuthor Commented:
Thanks all!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.