Starting to work with OO and Class Heirarchy..

Started by
1 comment, last by Guzba 21 years ago
Im wondering, with inheritence and class heirarchy would i organize stuff like this:
    
class CSystem
{
protected:

	HDC       hDC;
	HGLRC     hRC;
	HWND      hWnd;
	HINSTANCE hInstance;

public:

	CSystem(HINSTANCE Hinstance);

	void KillWindow(void);
	bool MakeWindow(void);

	HDC  GethDC()  const;
	HWND GethWnd() const;

	class CGraphics
	{

	};

	class CInterface
	{

	};

	class CCamera
	{

	};

	friend LRESULT CALLBACK WndProc(HWND	hWnd,
									UINT	uMsg,
									WPARAM	wParam,	
									LPARAM	lParam);
};
    
and if i do organize it like that would i need a constructor for each class? if you have any other information on class heirarchy please tell me! [edited by - Guzba on March 23, 2003 1:37:18 AM] [edited by - Guzba on March 23, 2003 1:37:55 AM]
"I never finish what i sta.."Computer:ATI Radeon 9700 PROP4 2.66 GHz512 RDRAM
Advertisement
Generally you wouldn''t nest classes like that. Usually you just create separate classes, each in their own file. Your example there doesn''t actually contain any graphics, interface, or camera functionality, as it only defines the class without declaring an instance of those classes.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]
There is Object Oriented Programming (OOP) and Object Oriented Design (OOD). Generally a book does well at one or the other. Generally a book on OOP does a good job of explaining the syntatic requirements and the semantics that syntax specifies. They don''t do as well at explaining why OOP and how to break a problem down into a set of classes that facilitate implementing a solution to that problem. That is what OOD is all about. They often run fast and loose with the syntax. They may use OOP concepts that are not implemented in one language, but is in another. There focus is on describing the problem and designing a solution, not actually implementing it.

So I would suggest getting a book on OOD. That should really be the starting point. Personally I like Object-Oriented Analysis and Design with Applications (2nd Edition)
by Grady Booch
. It doesn''t teach C++, but it does a good job of explaining why objects and how to use them to solve problems. It uses a pseudo-language and starts with a problem described as they are in the real world, i.e. "I would like something that works sorta like this." It then walks you through arriving at a detailed design read to program to solve that problem.

It is a totally differant approach. Not that book specifically, but rather OOD in general. It is easier to learn the syntax when you understand precisely what you want to do and it is simply a matter of figuring out how to get the language to do it. It is then like learning a second or third programming language. You know you need a for loop so what is the syntax in this language for a for loop. Whatever the syntax you are most likely going to have an initializer, a limit and an increment. OOD is a difficult topic. You won''t read a book an instantly understand how to solve any problem of any complexity using OO techniques, but at least you will be pointed in the right direction.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement