Google Answers Logo
View Question
Q: Visual Basic and C++ as Object-Oriented Languages ( Answered 4 out of 5 stars,   2 Comments )
Subject: Visual Basic and C++ as Object-Oriented Languages
Category: Computers > Programming
Asked by: tigers-ga
List Price: $9.50
Posted: 30 Jul 2002 09:05 PDT
Expires: 29 Aug 2002 09:05 PDT
Question ID: 46905
What are the risks and benefits of object-oriented languages using C++
and Visual Basic as examples.  More specifically why does C++ violate
the very nature of true object-oriented languages and why is VB
considered an object based event driven language rather than a true
object-oriented language?
Subject: Re: Visual Basic and C++ as Object-Oriented Languages
Answered By: j_philipp-ga on 30 Jul 2002 10:43 PDT
Rated:4 out of 5 stars
Hello Tigers,

As to any programming concept, it should be balanced using solid
theory, as well as project-oriented pragmatism. So in short, the risks
and benefits of the Object Oriented Paradigm in programming are just
that; it's a good solid theory, while it could get in the way of
project-oriented pragmatism in smaller software projects.

Time-critical, well-defined and clearly limited projects can suffer
from overtly theoretical approaches. But then again, it's rarely the
case that a programmer or management sees those limits, and more often
than not they will extend the original scope. In that case, it is good
to have started a solid basis, because people don't like to just throw
away older work; quite the opposite, they tend to copy existing
concepts found in a project, and at times bad code ends up in
otherwise good systems, which now can begin to "rot" from inside.

Before we go to the risks and benefits of OOP, here is an overview of
what Object Oriented Programming actually means:

What is Object-Oriented Software?

Object-Oriented Programming Concepts

What is Object-Oriented Programming?

Now, the specific risks of OOP, Object Oriented Programming, are:
- it's harder to understand if you're a programmer who never used it
- concentrating too much on the theoretical approach can shift the
focus away from real problems at hand
- it can be misused, like any programming approach (e.g. too complex
relationships, overuse of multiple-inheritance)

The benefits of OOP are:
- data encapsulation using the "black box" of an object
- restricted name-spaces
- often: more easily understood, structured code

What you need to keep in mind is:
- the lack of OOP expressed in programming language syntax does not
mean the actual code written is not object oriented
- any concept can be misused, and languages supporting object oriented
features can be used to write very linear, procedural programs

The last point brings us to why some would consider C++ violating the
nature of object oriented languages: C++ is rooted in C. While it
brings Object Oriented Programming to the C language, it does not get
rid of everything that might be considered historical these days --
and while that allows for very speed-optimized programs in some cases,
it also means there are some additional pitfalls when it comes to OOP.
You can move around them, or fall right in.

Same is true with Visual Basic, with one major exception -- as opposed
to C++, many do not even call it OOP. Up until version 6 of VB, there
is a lack of certain concepts available in "real" Object Oriented
languages. Most prominently, this includes inheritance; "an employee
is a kind of person, so my employee code can inherit and therefore
elegantly reuse my person code".
However in the newest release of VB (VB.NET, or VB7), these OOP
concepts are available.

It needs to be emphasized here that OOP stays a choice of programming
style for an individual programmer; there is simply no programming
language available that will force or teach one to be a good
programmer, or that will lead your way to OOP.

I hope this helps!

Search terms:
    "what is oop"
    vb oop
    "best oop"
    "c/c++ vs java"
    "c++ vs oop"

Request for Answer Clarification by tigers-ga on 30 Jul 2002 14:55 PDT
Could you give me more detail on why VB is considered and object-based
event driven laguage rather than a true object-oriented language, any
specific examples would be great.  Thanks for your help!

Clarification of Answer by j_philipp-ga on 30 Jul 2002 15:52 PDT
Hello Tigers,

In VB, you can visually design forms, by putting form elements on
them. This could be a button to click on. Such button can be called an
object, since it has methods and properties. E.g. a button property is
the text on the button:

    myButton.caption = "Click Me"

And a button method is:


(If you call this method "setFocus", the button will receive the

Now, what does event-driven mean here?
If you click on the button, an event is raised:

    Private Sub myButton_Click()
        MsgBox "You clicked the button"
    End Sub

This event lets you execute further code, like display a message-box
reading "You clicked the button". The function above is therefore
called the "event-handler", because it sits there silently until the
user does something (or another command raises the event). Events are
not non-OOP; rather, they can go hand in hand with an object oriented

But can you also implement your own classes in VB, to instantiate new
You can, but as I pointed out, without inheritance. This can be
sufficient in many cases:

    Dim myOutput As myOutputClass

    ' instantiate object using class code below
    Set myOutput = New myOutputClass
    myOutput.text = "Hello World"

    ' class code (separate file)
    Private m_text As String
    Public Property Let text(ByVal text As String)
        m_text = text
    End Property
    Public Sub outputText()
        MsgBox m_text
    End Sub

The actual use of this sample class is rather small; typically, a
class also has hidden methods (functions) that do some more of the
"behind the scenes" work.
But now compare the following two approaches to see the limitations:

Object composition:
- "has a" relationship: "A bike has a saddle"

Class inheritance:
- "is a" relationship: "A bike is a vehicle"

In other words, a saddle would not need to be able to do everything a
bike can; while a bike should be able to do everything a vehicle can.
In programming, the latter case is implemented using class
inheritance. This means reusing existing code to avoid redundancy, and
keeping the system flexible and open to easily implemented future

Now to connect this back to our button example, in Visual Basic up to
version 6, we would reach the limit of easily implementing a very
special button that provides much of the old functionality, but also
some of our own new functionality. We can not extend, or override
existing behavior; we can only use object composition (wrapping the
button with our own class) to simulate this, which is not quite as
The only good thing about this limitation is that it avoids some
occasions on which a programmer might otherwise use class inheritance
on a "has a" relationship, which would make the code unnecessarily
complex to maintain.
But, like I mentioned, the newest version of VB implements
inheritance, and therefore becomes a "real" OOP language.

Hope this helps!
tigers-ga rated this answer:4 out of 5 stars

Subject: Re: Visual Basic and C++ as Object-Oriented Languages
From: wengland-ga on 30 Jul 2002 14:58 PDT
Visual basic uses objects to respond to and create events.  It does
not allow you to inherit or create new objects based on already
existing objects.  Thus, it fails to meet one of the basic tennents of
OO design - code reuse / inheritance.
Subject: Re: Visual Basic and C++ as Object-Oriented Languages
From: bribold-ga on 16 Aug 2002 07:24 PDT
Most tution, examples and discussions on VB are based around its form
handling abilities. Indeed when you start a VB project, you are
presented with a form ready to use. It's strangely inevitable that any
example you'll ever see in VB relates to the GUI. This belies the fact
that VB is a general purpose language. Calling it an "event driven
language" is perhaps done by those who only see the surface of VB. It
is not event driven, you choose to bind events to it. It makes GUI
events and interactions very simple to use within a limited sphere.
You can create many kinds of events for all kinds of objects in VB if
you so choose. You can create raw COM dlls, which are not generally
GUI based and ActiveX controls which are. You can also write
procedural, non-gui programs in the old style. These comments are
normally made by fairly limited detractors of VB who repeat what
they're told generally (because they defintely won't get their hands
dirty with it). I'm not a great fan of VB. It has some great
weaknesses concerning its power and OO strucutre and semantics. A
lesser known fact of VB is that even when compiled, it produces some,
frankly, dreadful code. It has massive entry and exit frames around
its functions (when a function is compiled  to machine code, the
current chip state has to be presevered and restored when a entering
and leaving a function). A lot of this has been radically changed in
.NET (which I believe is excellent in principle, although I'm waiting
for Microsoft to hamstring it).

I heartily agree with J_phillip concerning discipline. You can achieve
any result using any language, some with a lot more twisting and
turning than others. Effectively OO embodies a methodology: It's a
discipline for separating concerns in your code. This was always
achievable even in C, although you had to be very disciplined to make
it consistent. Consistency is an important Grail in software
developement due to the varying degree of talent of programmers in the
industry. There are no 'good' or 'bad' languages in essence - it's up
to you to use them wisely. They all have their talents and their
failings. Object Orientation is a wonderful way to ORGANISE yourself -
it does not do the coding for you, however. Software Engineering is
NOT a science, as many make out: It is a craft. Like furniture making,
there is a base set of knowledge required to begin. After that it's up
to you to make nice chairs and tables. You can do that with an knife
(if you're very skilled) a lathe and template (less skilled) or a
robot laser-cutting furniture maker (if you're not skilled and like
your chairs all the same).

In fact the biggest failing of languages is their implementation on
different platforms. Long long ago, there was an old war between
Microsoft and Borland over their C, C++ and assembler languages. Guess
who's stuff wasn't very good but who conquered the world anyway? I
remember HP had a C++ unix variant that was so bad I used to cry when
I was compiling programs.

I like lots of languages. C++ has great power - but it is TWO
languages in one. You can (nearly) write clean OO code in it (no
garbage collection), and it also gives you the power of C. C has what
"managed" (as Microsoft now calls them) languages don't - pointers.
People hate pointers these days. Why? Because people tended to forget
to clean up after themselves making for reall bad programs. Has Java
et al stopped all the problems? No, the lack of talent is still there,
the problems are new. Pointer based techniques are incredibly
powerful, but you have to be careful with them. Ask a games programmer
what he/she thinks of the lack of direct memory manipulation.

If you want to see a what other concepts are possible with languages,
here's some favourites:

Smalltalk (very old) is a picture for elegance and it embodies every
fine principle of OO (it's just a little dull for me).

Python. This really rings my bell. It's a lovely little language, full
of amazing ideas and techniques. Heres one very very very simple one:
The comments in your code.. they can become part of the software - you
can access them in real time if you want - talk about not wasting
anything! Also you can BUILD class structures on the fly - add members
and methods as you want. You can get really complicated really easily
and clearly in Python. It's not the most powerful language in the
world, but it's a beauty. It's fun to use. It got massive support and
huge numbers of libraries at the moment. It's being taken very
seriously too. The community around it have a great sense of fun and

If your into curious languages in general, check out 3D Studio Max's
MaxScript.. It's from an unusual genre - the expression based
language. There are no statements - just expressions (so a 'for' loop
returns a value!). It's not the best for OO, but it has some
interesting ideas.

There, see - that's more than you asked, so I think I've started
ranting.. I'll stop now.. Hope that was of interest or use.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy