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?
 
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.
0
 
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.
e.g.
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.
0
 
Fabrice LambertFabrice LambertCommented:
Hi,

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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 ......?
0
 
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.
0
 
Dave BaldwinFixer of ProblemsCommented:
Fred, now you know why OOP really means Oops!
0
 
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.
0
 
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.
0
 
Fred MarshallPrincipalAuthor Commented:
Thanks all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.