To start off, I will never use MFC unless paid to do so.

All of the Win32 app's that I have created have been very small applications. I am going to develop what could end up being a very large application. And I have mostly written programs structured as a C program instead of C++. Recently I have started to learn/read about 'Design Patterns' from my boss. One of the books I have been reading is Design Patterns, ISBN #0201633612.

So needless to say I am wanting to figure out a way to design my program before I start.

I have an example that uses the last parameter of CreateWindowEx, they store a pointer to an object that will process all of the messages.

I was curious to get you guys opinion on this subject. Possibly some design ideas, whether they be OO or along the lines of C.

Posted on 2003-06-26 21:57:15 by gorshing
It depends on the type of program you're working on and the types of data you need. Needless to say that you also have to take into account what your company/boss/professor/... requires you to do/use.

There are a lot of fuss about OOP nowadays. Before I post a link, I want to say I'm not anti-anything. I believe its good to have a different perspective. Try reading this article - rather long but will make you think twice.

It's only useful for a specific purposes like in the fields of 3d modeling, graphic applications... where objects are given the "priority" - tweak shapes, rotate, transform, scaling, morphing(as in the case of most diagramming/flowcharting software).


Even though you can produce anything without the use of OOP, I believe the overhead code by using the OOP paradigm *doesn't affect*(Posted on 2003-06-27 00:54:52 by arkane
In my opinion, OO can really improve readability, structure and maintainability of your code. Of course not in all cases but I've used it successfully in many occasions.
Design patterns are really nice things, they proved to be constructs that work well so why not use them? The Gang of Four book (GoF) you mentioned is the first book that described 20 basic design patterns. It's probably well worth reading (I don't have it myself though).
Also have a look at this site:

It describes the same 20 patterns as the GoF book, but with java examples so it's a bit more recent. I found it to be a very good explanation of the patterns.

Using patterns with the win32 API isn't really possible I think. Most importantly, the win32 API is not object oriented. So you will need to write OO wrappers if you want to use patterns with it. It is possible, but a lot of work. MFC has made an attempt to do that, personally I don't like MFC much either, but at least it's OO. If you want more lightweight object oriented wrappers, have a look at WTL (based on ATL). Problem with WTL is that there's hardly any good documentation... Another alternative is using other GUI libraries (most are clossplatform), like wxWindows. Usually they are OO too.

Finally you could write your own wrappers, but realize the amount of work involved (I made an attempt once but it's just too much work). Or you could just use it where it matters, like you probably tried already with the CreateWindowEx extra parameter.

As design tips, have a look at the model-view-controller pattern. Java's Swing uses this all the time. It is a pattern to keep represented data consistent in an easy way. Basicaly the model is the data you want to represent, the view is the way you represent it (listview, treeview, edit box?) and the controller is the glue between them. The model and view have an subject-observer relation, where the model notifies the view whenever its data changes. This way, the view is always up to date. Likewise, when the user modifies something in the view, it has to tell the model to update itself with the new data. Using this pattern the views and models are nicely seperated, and it becomes irrelevant what the view exactly is or how many views there are.

Swing is full of design patterns (probably a bit too much sometimes, it's slow as hell ;)). You might want to take a look at that to get some ideas as well.

Posted on 2003-06-28 05:59:31 by Thomas