|
C++ Fractal |
Andrei Ellman
Member #3,434
April 2003
|
Here's a forum-game-type-thing for ya's. You know how the C++ language has many different ways of doing the same thing, and that object-oriented programming has the pitfall that it becomes tempting to over-engineer even the simplest task? What I propose we do is that we each take it in turns to contribute to the over-engineering of a simple program by re-writing it. Each person adds one additional layer of abstraction and posts their code here. Then the next person engineers it further by adding an extra layer of abstraction. You could say that adding each additional layer of abstraction to the C++ code is like zooming in on an image that becomes more detailed the more you zoom - a bit like a fractal - hence the name C++ Fractal. The program I've written below is a simple program to verify that 1+1 does indeed equal 2. Note that the code I've given is purely in C. There is no obligation for the next person to switch over to C++, but sooner or later, the switch to C++ is going to occur. AE. -- |
Billybob
Member #3,136
January 2003
|
|
CGamesPlay
Member #2,559
July 2002
|
Gimmie a minute... [append]
[append] -- Ryan Patterson - <http://cgamesplay.com/> |
Steve++
Member #1,816
January 2002
|
|
Steve Terry
Member #1,989
March 2002
|
In your template class you have your enum defined ast Result yet you are returning a Status. Just thought I'd point out the bug ___________________________________ |
Carrus85
Member #2,633
August 2002
|
Bridge Pattern: Main.h class MainImpl; class Main { private: MainImpl* impl; Main& operator=(const Main&); Main(const Main&); public: Main(); ~Main(); int run(int argc, char *argv[]); }; MainImpl.cpp
main.cpp #include "Main.h" int main(int argc, char *argv[]) { Main obj; return obj.run(argc, argv); }
EDIT:
|
Michael Faerber
Member #4,800
July 2004
|
- OutputDevice (derived classes) main.cpp: #include "Main.h" int main(int argc, char *argv[]) { Main obj; return obj.run(argc, argv); } Main.h:
MainImpl.cpp:
OutputDevice.h:
[EDIT] [EDIT] -- |
Indeterminatus
Member #737
November 2000
|
Used a policy (templates again): Status.h:
MainImpl.cpp:
Warning: As I'm not on a computer with a C++ compiler, I couldn't test it, so it might be that it doesn't even compile. The rest of the files were unchanged. _______________________________ |
Ariesnl
Member #2,902
November 2002
|
This will become something like skynet eventually Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard) |
Steve++
Member #1,816
January 2002
|
Quote: In your template class you have your enum defined ast Result yet you are returning a Status. Just thought I'd point out the bug Oops. I didn't compile. |
Marcello
Member #1,860
January 2002
|
Don't worry about it, I don't think that printf{"Oh dear, mathematics is falling apart."}; from the original post is valid C either. Marcello |
Thomas Fjellstrom
Member #476
June 2000
|
Ah the joys of over engineering. -- |
BAF
Member #2,981
December 2002
|
It's amazing how bloated a simple program can be in C++. Why don't we switch to Java, to give a better illusion of bloat and slowness? |
Simon Parzer
Member #3,330
March 2003
|
Quote: Don't worry about it, I don't think that printf{"Oh dear, mathematics is falling apart."}; from the original post is valid C either. It would work if the C code was interpreted instead of compiled. |
|