Archived

This topic is now archived and is closed to further replies.

luke_o_rama

Abstraction in C++

Recommended Posts

Well, let''s see... An abstract class, by definition is simply a class that has one or more pure virtual functions. Also, objects cannot be created from an abstract class (though you can create a pointer to an abstract class), but other classes can be derived from them. As far as their use, their great for creating a common object interface (much the way interfaces are used in Java). With all this in mind, you could have a pointer to an abstact class pointing to a list of objects derived from that class. They would all have a function that they all would inherit from that abstract base class, but you would be able to define each function differently. Thus, each derived class could act in a completely different way than other classes derived from that base abstract class when the same function is called for each.

Share this post


Link to post
Share on other sites
Oops. I guess I misunderstood the question. When you say abstraction, are you talking about abstraction in object oriented design or programming?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The concept behind abstraction is to separate
interfaces from implementation so that each vary separately
so that you can more easily intermix related and un-related
classes/objects/components

this is to :
1) promote re-use
2) when classes are very tightly coupled fixes or interface
or implementation changes lead to problems in other classes
(this can be anything from improper working (ie instead
of Effect A (expected) you get Effect B (unexpected))
to being forced to re-compile as the other classes interface
has changed so significantly ''yours'' no longer works (this can
be a nightmare if you were relying on an external
library whose interface changed between versions)

also,
consider portability issues ..
you are using DirectX on windows, you want to port your
app to OpenGL on *n?x
if you create an abstraction of hardware rendering
(in my lib this is an abstract class called ''Renderer'')
then you implement 2 separte versions of Renderer for DX and Opengl then your app can decide (at run-time) which implementation to go with (you will of course need to
create a few other abstractions, for window-creation, and whatnot)
but what you have done is made it significantly simpler for
potential future expansion , even expansion you may not
have originally planned for (and if you''re a library writer, it can very well be expansion that you had not intended and someone
else could take your library and expanded it to some platform
or implementation you had not considered)

on the concepts of abstraction, good object-oriented abstraction
and how it relates to computer games, i recommend these 3 books

1)
Design Patterns by Gamma, Vlissides et.al.
ISBN: 0201633612
2)
3d Game Engine Design by David Eberly
ISBN: 1558605932
3)
Game Architecture and Design by Andrew Rollings and Dave Morris
ISBN: 1576104257

-----
MachinShin
--vat
machinshin@onebox.com

Share this post


Link to post
Share on other sites
Here''s a nice definition of abstraction:

"The process of picking out (abstracting) common features of objects and procedures. A programmer would use abstraction, for example, to note that two functions perform almost the same task and can be combined into a single function. Abstraction is one of the most important techniques in software engineering and is closely related to two other important techniques -- encapsulation and information hiding. All three techniques are used to reduce complexity."

Taken from the Webopedia, see http://webopedia.internet.com/TERM/a/abstraction.html.

Share this post


Link to post
Share on other sites