What is the proper way to add a form to an existing class?
-
Hi. I'm using Visual Studio C++/CLI. I have a well developed class that now has a need to have a user interface for it. Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class? Thanks, Buck
-
Hi. I'm using Visual Studio C++/CLI. I have a well developed class that now has a need to have a user interface for it. Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class? Thanks, Buck
BuckBrown wrote:
Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class?
Buck, what's up dude? Ever heard of Object Oriented Design Principles, Best Practices, Separation of Concerns, Design Patterns, Model-View-Controller? Any of this ringing any bells with you? You don't tightly couple a "class" with the presentation layer of your design, it's not considered Best Practice and there are Patterns like MVC that represent solutions for this.
led mike
-
BuckBrown wrote:
Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class?
Buck, what's up dude? Ever heard of Object Oriented Design Principles, Best Practices, Separation of Concerns, Design Patterns, Model-View-Controller? Any of this ringing any bells with you? You don't tightly couple a "class" with the presentation layer of your design, it's not considered Best Practice and there are Patterns like MVC that represent solutions for this.
led mike
Hi Mike, Just so you know, I first learned programming using assembly on a state of the art Intel 8085 and our operating system was CP/M (that's what it was called before Microsoft bought it and renamed it MS-DOS). Over the years I have been forced to learn various programming languages on Data General, VAX, UNIX, and MS-DOS boxes, but all of the OO stuff was invented long after I got out of college. So the fact that I'm an over 50 microelectronics engineer with a EE degree and not a new Computer Science graduate, I can state with confidence that with the exception of Object Oriented Design Principles I've never heard of any of those terms before (nor whatever MVC means). You even mention a "presentation layer". I have never heard anyone use that term before. IO, User Interface, GUI sure, but "presentation layer"? I don't understand what you mean by "you don't tightly couple a class with the presentation layer". Visual Studio's forms designer seems to make things very tightly coupled. Anyways, if you could dumb down your responses for me that would be cool. Thanks, Old Buck And my applications always work and do what they were designed to do.
-
Hi Mike, Just so you know, I first learned programming using assembly on a state of the art Intel 8085 and our operating system was CP/M (that's what it was called before Microsoft bought it and renamed it MS-DOS). Over the years I have been forced to learn various programming languages on Data General, VAX, UNIX, and MS-DOS boxes, but all of the OO stuff was invented long after I got out of college. So the fact that I'm an over 50 microelectronics engineer with a EE degree and not a new Computer Science graduate, I can state with confidence that with the exception of Object Oriented Design Principles I've never heard of any of those terms before (nor whatever MVC means). You even mention a "presentation layer". I have never heard anyone use that term before. IO, User Interface, GUI sure, but "presentation layer"? I don't understand what you mean by "you don't tightly couple a class with the presentation layer". Visual Studio's forms designer seems to make things very tightly coupled. Anyways, if you could dumb down your responses for me that would be cool. Thanks, Old Buck And my applications always work and do what they were designed to do.
Hey Buck, sorry about that, I had no idea. Most of those terms can be googled and wikipedia is a good introduction to most of them as well. http://en.wikipedia.org/wiki/Separation_of_concerns[^] http://www.google.com/search?hl=en&q=wikipedia+design+patterns&btnG=Search[^] http://en.wikipedia.org/wiki/Model-view-controller[^] http://en.wikipedia.org/wiki/Presentation_layer[^] Prefer Loose Coupling[^] If you are doing .NET development you should check out the Microsoft Patterns and Practices Center[^] In OOD the simplest example of how to avoid tight coupling is if you have two classes that represent different things so there is no reason for them to "know" of each other, they have no relationship or association.
class A class B
Now you find a use model or activity for which the solution can use both of them. Bad Practice would be to modify either one or both to use them in combination resulting in a relationship or association. Best Practice would be to create a 3rd class that has a relationship to both the others and implements the solution combining the first two classes. This maintains the isolation between the first two classes.class A class B \
-
Hi. I'm using Visual Studio C++/CLI. I have a well developed class that now has a need to have a user interface for it. Normally I will determine if I need a form associated with a class when I create the class, so the class is created as a System::Windows::Forms::Form. But now I have a class that I did not think would need a form associated with it so it was defined as a simple C++ ref class. What is the proper way to add a form to the class? Should I create a new UI Forms based class and cut and paste everything in my existing class into it? Or is there a simple way to instantiate a new form as a method of the existing class? Thanks, Buck