Announcement

Collapse
No announcement yet.

Classes, Types and encapsulation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Classes, Types and encapsulation

    Hi,

    I was experimenting today with a class that I am writing. The class requires access to a TYPE structure via an INSTANCE variable. No big deal, that is pretty straight forward to do.

    The "problem" is that the TYPE definition can not be located within the CLASS so therefore it will be exposed to the rest of the program. No big deal if the Class is located in a DLL, but my Class is in a simple #INCLUDE that I would like to put into any new source code that I write or share with others for them to include in their code bases.

    My concern involves the TYPE/END TYPE now having the potential to cause a naming conflict with an existing TYPE in someones code. In the grand scheme of things it is no big deal other than dealing with the renaming thing, and I guess the odds are pretty low if give the TYPE a unique name (maybe use a GUID?) but the potential exists nonetheless.

    I guess I just wanted to throw it out there that maybe TYPEs could be defined within CLASSes so that their definition is private to the CLASS. This would be consistent with the idea of encapsulation? Maybe I'm making too much of this but its Friday afternoon and I have nothing else to talk about.
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

  • #2
    Would it buy you anything to make a class out of the type and inherit from the class (type) (now a base class)?
    Fred
    "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

    Comment


    • #3
      I did some encapsulation of Ketil's Grid control and I created a class for just the column UDT. I create a instance of it in the CLASS METHOD CREATE of the Grid class. I've used this method of using a class instead of a udt in a couple other code snippits and it works fine.

      James

      Comment


      • #4
        Originally posted by Fred Harris View Post
        Would it buy you anything to make a class out of the type and inherit from the class (type) (now a base class)?
        Maybe. Not sure at this point because I haven't converted the TYPE code snippets to see how good/bad it will translate to a Class. I am looking at Terry Fritts/Florent's code that sends email directly based on MX records. He uses a couple of Types, one of which is used as a buffer to pass to the "sendto" function in the ws2_32.dll

        I just need to readjust my thinking a little bit away from TYPEs.
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.
        http://www.planetsquires.com

        Comment


        • #5
          Originally posted by jcfuller View Post
          I did some encapsulation of Ketil's Grid control and I created a class for just the column UDT. I create a instance of it in the CLASS METHOD CREATE of the Grid class. I've used this method of using a class instead of a udt in a couple other code snippits and it works fine.
          Cool! That's a nice grid control. It seems like just about all the new code that I am writing these days is based around Classes rather than Types. Nice to not to have to deal anymore with hacks and kludges to access dynamic strings and arrays in Types - simply convert it to a Class.
          Paul Squires
          FireFly Visual Designer (for PowerBASIC Windows 10+)
          Version 3 now available.
          http://www.planetsquires.com

          Comment

          Working...
          X