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...
Console Driver Problem
Re:Console Driver Problem
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.
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.
Every good solution is obvious once you've found it.
Re:Console Driver Problem
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.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.
Re:Console Driver Problem
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.)Candy wrote: This would be called an implementation of a design pattern called "singleton".
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.Use design patterns in your OO software (all of it), it helps build good designs when used properly.
They are nice, but as everything, they should be understood as a tool, not a religion.
Every good solution is obvious once you've found it.
Re:Console Driver Problem
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?Solar wrote: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.)Candy wrote: This would be called an implementation of a design pattern called "singleton".
Re:Console Driver Problem
Codemaster Snake wrote (emphasis is mine):Candy wrote: Why do you claim it's a bad place for a singleton?
I assume he means to make multiple consoles possible, like those offered by Linux if you press Alt-F1, Alt-F2 etc.I have developed a C++ console mode vriver and it has a constructor whicxh gets initialized whenever an object of Console class is created...
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.
Every good solution is obvious once you've found it.
Re:Console Driver Problem
No I don't want multiple consoles...
Can anyone plz provide some good example for it or a weblink
Can anyone plz provide some good example for it or a weblink
Re:Console Driver Problem
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.
Every good solution is obvious once you've found it.
Re:Console Driver Problem
Naturally, a singleton is only a nice wrapper around a global object in the most common implementation.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.