Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. What is the proper way to add a form to an existing class?

What is the proper way to add a form to an existing class?

Scheduled Pinned Locked Moved Managed C++/CLI
designquestioncsharpc++visual-studio
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    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

    L K 2 Replies Last reply
    0
    • B BuckBrown

      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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • L 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

        B Offline
        B Offline
        BuckBrown
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • B BuckBrown

          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.

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          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    \

          1 Reply Last reply
          0
          • B BuckBrown

            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

            K Offline
            K Offline
            killabyte
            wrote on last edited by
            #5

            Easy way would just be to make a new form class and make the class a member of the new form class. ugly? yes. best practise? no. will it do the trick? probably :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups