Sharing properties across classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Morten Snedker

    Sharing properties across classes

    How do I share a property across classes?

    For example I'll have three classes:

    - Settings
    - Class1
    - Class2

    Class1 will initiate the class Settings with a New Settings and will
    followingly set the properties in the class Settings.

    After Class1 has set the properties of Settings, Class2 will use these
    already set properties, but without a New.

    How do I access the property values set by Class1 - from Class2? I
    should I consider another approach?

    Regards /Morten Snedker

  • Patrice

    #2
    Re: Sharing properties across classes

    Does it make sense to have multiple instances for the Settings class ?

    If not, try :
    http://msdn.microsoft.com/en-us/libr...95(VS.71).aspx ("Shared
    Members") or


    In particular with solution #1 you don't even have to create an instance.
    You'll just use Settings.MyShar edProperty...

    --
    Patrice


    "Morten Snedker" <morten.snedker @gmail.coma écrit dans le message de
    groupe de discussion : Ohi1BCYSJHA.588 @TK2MSFTNGP06.p hx.gbl...
    How do I share a property across classes?
    >
    For example I'll have three classes:
    >
    - Settings
    - Class1
    - Class2
    >
    Class1 will initiate the class Settings with a New Settings and will
    followingly set the properties in the class Settings.
    >
    After Class1 has set the properties of Settings, Class2 will use these
    already set properties, but without a New.
    >
    How do I access the property values set by Class1 - from Class2? I should
    I consider another approach?
    >
    Regards /Morten Snedker
    >

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: Sharing properties across classes

      Morten Snedker wrote:
      How do I share a property across classes?
      >
      For example I'll have three classes:
      >
      - Settings
      - Class1
      - Class2
      >
      Class1 will initiate the class Settings with a New Settings and will
      followingly set the properties in the class Settings.
      >
      After Class1 has set the properties of Settings, Class2 will use these
      already set properties, but without a New.
      >
      How do I access the property values set by Class1 - from Class2? I
      should I consider another approach?
      >
      Regards /Morten Snedker
      >
      Take a look at the singleton pattern. By making the Settings class a
      singleton, the Class1 class would get the instance of the Settings class
      (and thereby creating it as it's the first use of the class). Then the
      Class2 class could get the instance of the Settings class, and this
      would be the same instance as the Class1 class initiated.

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • Michel Posseth  [MCP]

        #4
        Re: Sharing properties across classes

        You could also just use a module ,,, :-|

        or just pass the properties to the other classes as parameters in the
        constructor

        just 2 extra simple solutions for your "problem"

        HTH

        Michel Posseth



        "Morten Snedker" <morten.snedker @gmail.comschre ef in bericht
        news:Ohi1BCYSJH A.588@TK2MSFTNG P06.phx.gbl...
        How do I share a property across classes?
        >
        For example I'll have three classes:
        >
        - Settings
        - Class1
        - Class2
        >
        Class1 will initiate the class Settings with a New Settings and will
        followingly set the properties in the class Settings.
        >
        After Class1 has set the properties of Settings, Class2 will use these
        already set properties, but without a New.
        >
        How do I access the property values set by Class1 - from Class2? I should
        I consider another approach?
        >
        Regards /Morten Snedker
        >

        Comment

        Working...