• Advertisement
Sign in to follow this  

Wanted: The perfect OOP application

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, those of you who know me well know that I'm a fairly good programmer, and have more than a passing familiarity with OOP. But in all the medium-to-large software projects I design, I tend to employ an amalgam of OOP and procedural programming. This will undoubtedly get me torn to bits by OOP zealots one day, but it works for me so I continue doing it. Obviously, though, others take a more hardline and pure approach, and it seems to work well for them; so it's something I should at least try. The problem is, I just don't have the time or the willpower to design and implement an entire medium-sized software project in pure or mostly-pure OOP just to satisfy my curiosity. Ideally, I'd spend time looking over the code of someone else's application, but I have no idea where to look for an application that embodies the best of the pure OOP paradigm. So I'll throw it out to you guys: where can I find an application whose source code is really well-designed OOP, without concessions or compromises? Preferably a game, but anything'll do as long as it isn't TOO boring. Oh, and this isn't an April Fool's joke. It seems to be obligatory to add that to every freakin' message I post today.

Share this post


Link to post
Share on other sites
Advertisement
I am no expert, and probably wouldn't know a perfect OOP app if it bit me in the ass.

That said, my first thoughts go towards something written in Java, as that tends to harbor programmers with strict OOP tendancies.

Narya is a public game framework used in the commercial MMORPG Puzzle Pirates. I cannot speak to it's OOPness, or anything else really; just that it exists, and is likely to fit your requirements.

Share this post


Link to post
Share on other sites
I'm a little leery about looking to frameworks or libraries. Good OOP frameworks and libraries abound; I've written a few of them myself. But I'd like to see something with client code as well, to get the whole picture.

Share this post


Link to post
Share on other sites
OGRE

(Object oriented Graphics Rendering Engine? Something like that.. )

Personally I found pouring through its code quite informative. It's got good documentation as well.

Share this post


Link to post
Share on other sites
I'll recommend that you not beat yourself up for understanding that there is more than one way to write code. Pick up a copy of "Multi-Paradigm Design for C++" by James Coplien. If you are attacked by OO zealots or functional zealots or any other form of purists, slap them across the face with the book until they withdraw.

With that said, practicing multi-paradigm design requires a mastery of multiple techniques instead of just one. Quoting the Functional Programming Koans:

'The Koan of Side Effects

A student of FP came to Daniel de Rauglaudre and asked how to achieve FP Nature. Daniel replied, "to achieve FP Nature, you must learn to program without side effects and other imperative features". So the student went away to learn how to program in this style. He studied very hard so he could rid his programs of references and for-loops. He struggled to only use let bindings and let rec loops. One day, in order to find inspiration, he was studying the code of the Masters, and in reading the source of Camlp4, he saw a number of uses of references and for-loops! He rushed back to Daniel de Rauglaudre and exclaimed, "How can you tell me not to use imperative features when you use them yourself!" Daniel measured the student carefully in his gaze and replied, "But I already know how to program without side-effects." At that moment the student was enlightened.'

Share this post


Link to post
Share on other sites
To help understanding, I'll also quote the answer to the Koan of Side Effects:

'The Koan of Side Effects

The enlightenment that Daniel helped the student achieve was this: If you do not learn to program without side-effects, you will not learn when to program with side-effects. Some functional languages, like Haskell are functionally pure, and do not offer any imperative features. However, OCaml (and ML) provides a mixed paradigm where you can program in both declarative and imperative styles, because sometimes it is convenient to do so. Once you have achieved mastery, you will know when it is appropriate to take advantage of that convenience.

If you are coming to FP from an imperative background you should remember that now you need to learn to think and do things a little differently than before. Until you feel comfortable doing so, it's best to avoid your old habits altogether, if possible.'


The enlightenment of the koan applies equally well to the OO vs Procedural debate. If you do not master OO, you will not know when it is genuinely appropriate to use procedural techniques.

Share this post


Link to post
Share on other sites
Your code is basically about objects talking to each other thru public interfaces while doing detailed stuff internally. Then you have objects that deal with polymorphic objects ie. who needs to know what and to what extent. Then you have whole/part objects where one object tells the whole what to do and it does it thru the use of its parts. There are two levels of algos. The one done thru public interfaces by objects talking to each other and thus solving a problem that way and the other algos which are internal to the objects. Think of the "talking" part as the highest level procedural function that has several lower level functions that describe the algo.

DoSomeAlgo()
{
DoFirst();
DoSecond();
DoThird();
}

Actor is an object that initiates DoSomeAlgo() then objA sends message go objB saying DoFirst(), then objB sends message to objC saying DoSecond() then objA sends message to objC saying DoThird().

That's why it's important to have collaboration diagram done first so that you can define your algo with objects and it's also why this is only the first part since at this time you might not know the internals of DoFirst() and the others. Once you figure out the internals they might change your public interface of existing objects. Simply because you have now more details to work with than before. Use cases are tied to the collaboration diagrams ofcourse. I wouldn't count on use case to define the objects from the use case description. I think sequence or collaboration diagram is more useful because you're describing the algo which is what you're after in the first place.

Share this post


Link to post
Share on other sites
Quote:
Original post by JD
Your code is basically about objects talking to each other thru public interfaces while doing detailed stuff internally.

Oh, I fully understand the basis of object-oriented design. I'm just interested in seeing real-life examples of it as it is applied to a pure-OOP development strategy.

Share this post


Link to post
Share on other sites
If the code involves win32 API, then it can't be made really OO :)

OO is not the only programming paradigm, sometimes generic programming using template yields better productivity.

Share this post


Link to post
Share on other sites
Quote:
Original post by Void
If the code involves win32 API, then it can't be made really OO :)


That's one big pile of horse manure mister.
You must be confusing the notation of calling member functions with '.' or '->' and the idea of OOP. Much of win32 really is based around an object notation
only that the calling conventions looks like:
DoStuff(Object, params);

instead of the more convinent:
Object.DoStuff( params);

but essentially they're the same you can do OOP in C or assembler you just lose
some notational convinence.

Share this post


Link to post
Share on other sites
Get the book "Agile software development: Principles, patterns and practices" by Robert C. Martin, it teaches good OOP design. In the book he does some great case-studys that you can learn alot from. And be sure to check out Object Mentor .

Edit: and oh, there are not such a thing as the perfect OOP application.

Lizard

Share this post


Link to post
Share on other sites
Give me some time to put up the revised version of my app's source code, Sneftel.

I do not claim to be perfectly OOP, as I find generic programming to be far more powerful, but at the moment I'm using a component-based microkernel approach, where everything is a component. I'm still refactoring quite a bit from the current version, and I have a lot of code to go through.

I have made very few compromises in terms of design quality. If you want to know more, let me know, its going to be at least a week before its available on my site.

Share this post


Link to post
Share on other sites
Some time ago, a finnish game developer closed its offices and released the source code to an incomplete but playable 3D game with its engine named Cat Mother. One can clearly see that the developers must have used Java before and follow the strict, non-compromise OOP approach you described.

There are very few examples which really deserve to called clean, perfect code. Ogre for example is nice, intuitive and convenient, but imho not at all pure OOP - just slightly more OOP as the typical game developer wannabe is used to ;)

One piece of code that really surprised me was Mojavi, a PHP based framework for developing web applications (eg. a CMS). Not only is it very pure OOP, but it is very convenient and easy to use at the same time. I didn't know that kind of code quality is within the range of those hacky PHP coders :P

-Markus-

Share this post


Link to post
Share on other sites
Quote:
Original post by Void
If the code involves win32 API, then it can't be made really OO :)

I'd agree that parts of the win32 API are definitely not OO.

In the past I have found that OO frameworks which wrap win32 windows non-OO functionality, like MFC (Microsoft Foundation Classes) and OWL (Object Windows Library Borland) are good examples of an OO alternative to non-OO code. Just compare a simple Win32 C app (e.g. scribble) with an equivalent C++ MFC or OWL app to get a good introductory appreciation of OO.

Share this post


Link to post
Share on other sites
My take is that you will never be able to create a true OO application in C++, simply by the fact that you need int main() to start it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Prototype
My take is that you will never be able to create a true OO application in C++, simply by the fact that you need int main() to start it.


OOP is essentially not a programming or an exact implementation strategy it actually more of a design issue.

Wikipedia has a quite nice article on it.

OOP is really language independant and can be expressed in mostly any programming language including asm and C.

Share this post


Link to post
Share on other sites
Quote:
Original post by DigitalDelusion
OOP is essentially not a programming or an exact implementation strategy it actually more of a design issue.

Wikipedia has a quite nice article on it.

OOP is really language independant and can be expressed in mostly any programming language including asm and C.
Quote:
Original post by Prototype
OOP is really language independant and can be expressed in mostly any programming language including asm and C.

Of course any turing complete language can mimic it, but I don't think that has anything to do with true OO programming. True OO should be forced upon you (not that I would favor that but you get the point). The mere fact that you have to call a function in C++ to create the primary object, seems inconsistent and therefore not 'truly' OO to me.

Surely this is just my private opinion as I don't feel particularly qualified to define standards :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Not Languages are OO, People are!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement