Page 1 of 1

Console Driver Problem

Posted: Fri Oct 21, 2005 2:19 am
by codemastersnake
Hello everybody!

Well I am developing a 32 bit PM OS and have already developed a Console driver for it....

I am developing my OS in C++....

Well my problem is :

I have developed a C++ console mode vriver and it has a constructor whicxh gets initialized whenever an object of Console class is created and what this constructor does is initializes the xpos and ypos variables with zero and then clears the screen and places cursor on the top left of the screen.....

I will also be devloping other drivers in C++ also say for Clock.... What I want is that when ever clock clase's object is created I want to put a message on the screen like in linux that clock mode driver is loaded in the memory... to do this I'll need console driver (but obviously) but if I creat anothe console object in clock class then the whole screen will get resetted and message will get printed on the top left of the screen....

what could I do to make this work....

I WILL USE CLASSES AND NOTHING ELSE....

plz help...

Re:Console Driver Problem

Posted: Fri Oct 21, 2005 2:30 am
by Solar
Obviously you cannot initialize a new console for the output, so you have to use an already existing one. How you solve this depends on where you want that output to end up.

One way would be to provide a static member function in class Console that returns a reference to a certain Console object - perhaps the first one initialized, or the one currently displayed.

Another would be to pass a reference to a Console object to the constructor of class Clock.

Re:Console Driver Problem

Posted: Fri Oct 21, 2005 3:50 am
by Candy
Solar wrote: One way would be to provide a static member function in class Console that returns a reference to a certain Console object - perhaps the first one initialized, or the one currently displayed.
This would be called an implementation of a design pattern called "singleton". Use design patterns in your OO software (all of it), it helps build good designs when used properly.

Re:Console Driver Problem

Posted: Fri Oct 21, 2005 4:55 am
by Solar
Candy wrote: This would be called an implementation of a design pattern called "singleton".
Nope. A Singleton is a design pattern ensuring that there can only be one instance of a class. (And it's the most over- and abused design pattern of all.)
Use design patterns in your OO software (all of it), it helps build good designs when used properly.
Emphasis is mine. You should be very familiar with OO programming before you start extensive use of design patterns. Nine out of ten pattern implementations I have seen were misplaced, didn't solve the problem at hand and / or introduced needless complexity.

They are nice, but as everything, they should be understood as a tool, not a religion.

Re:Console Driver Problem

Posted: Fri Oct 21, 2005 6:35 am
by Candy
Solar wrote:
Candy wrote: This would be called an implementation of a design pattern called "singleton".
Nope. A Singleton is a design pattern ensuring that there can only be one instance of a class. (And it's the most over- and abused design pattern of all.)
I would most certainly qualify a console controller as a place to use a singleton, since it's a class that may only be instantiated once for its proper function. Why do you claim it's a bad place for a singleton?

Re:Console Driver Problem

Posted: Fri Oct 21, 2005 7:03 am
by Solar
Candy wrote: Why do you claim it's a bad place for a singleton?
Codemaster Snake wrote (emphasis is mine):
I have developed a C++ console mode vriver and it has a constructor whicxh gets initialized whenever an object of Console class is created...
I assume he means to make multiple consoles possible, like those offered by Linux if you press Alt-F1, Alt-F2 etc.

That means there can be more than one Console object, but you'd need either a global variable or a class method to get "the right one". Class method is preferred, of course.

Re:Console Driver Problem

Posted: Sat Oct 22, 2005 5:13 am
by codemastersnake
No I don't want multiple consoles...

Can anyone plz provide some good example for it or a weblink

Re:Console Driver Problem

Posted: Sun Oct 23, 2005 3:03 am
by Solar
After reading this excellent article on the hubbub you can perform around the Singleton pattern you will perhaps agree that this pattern isn't really necessary, and that instanciating a single global Console object and using that might suffice. ;)

Re:Console Driver Problem

Posted: Sun Oct 23, 2005 5:02 am
by Candy
Solar wrote: After reading this excellent article on the hubbub you can perform around the Singleton pattern you will perhaps agree that this pattern isn't really necessary, and that instanciating a single global Console object and using that might suffice. ;)
Naturally, a singleton is only a nice wrapper around a global object in the most common implementation.