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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. OOPS concepts in c#

OOPS concepts in c#

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpquestion
11 Posts 4 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.
  • 9 9500394002

    I want to allow the class to create only one object instance. I want to make visible the class ouside the assembly but restrict to only one assembly. What needs to do? Please suggest me.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    Take a look at the Singleton pattern[^].

    One of these days I'm going to think of a really clever signature.

    1 Reply Last reply
    0
    • 9 9500394002

      I want to allow the class to create only one object instance. I want to make visible the class ouside the assembly but restrict to only one assembly. What needs to do? Please suggest me.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #3

      What does this have to do with OOPS concepts? What you are describing is such a basic request that it's part of the framework; we call them "static classes".

      public static class MySingleObjectClass
      {
      public static void PerformSomeAction()
      {
      }
      }

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      9 1 Reply Last reply
      0
      • L Lost User

        What does this have to do with OOPS concepts? What you are describing is such a basic request that it's part of the framework; we call them "static classes".

        public static class MySingleObjectClass
        {
        public static void PerformSomeAction()
        {
        }
        }

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        9 Offline
        9 Offline
        9500394002
        wrote on last edited by
        #4

        If we create static class , we cannot able to create instance. but ,my query is that instance should be created only one time and restrict to more than one.

        L 1 Reply Last reply
        0
        • 9 9500394002

          I want to allow the class to create only one object instance. I want to make visible the class ouside the assembly but restrict to only one assembly. What needs to do? Please suggest me.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #5

          If you want to restrict the class so that it can only be seen by one particular external assembly, you use internal to limit the scope to the current assembly, and then you implement InternalsVisibleTo[^] to link this to the specific assembly.

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          9 1 Reply Last reply
          0
          • P Pete OHanlon

            If you want to restrict the class so that it can only be seen by one particular external assembly, you use internal to limit the scope to the current assembly, and then you implement InternalsVisibleTo[^] to link this to the specific assembly.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            9 Offline
            9 Offline
            9500394002
            wrote on last edited by
            #6

            Are you suggesting InternalVisible to be used in the parent class? Up to my knowledge InternalVisible access modifier is not there in c#

            P 1 Reply Last reply
            0
            • 9 9500394002

              Are you suggesting InternalVisible to be used in the parent class? Up to my knowledge InternalVisible access modifier is not there in c#

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #7

              Did you even bother opening the link in the answer?

              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              D 1 Reply Last reply
              0
              • P Pete OHanlon

                Did you even bother opening the link in the answer?

                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #8

                No, because that would violate the rules of "spoon feeding".

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                P 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  No, because that would violate the rules of "spoon feeding".

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #9

                  Don't you just love my hopeless optimism?

                  *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                  9 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Don't you just love my hopeless optimism?

                    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                    9 Offline
                    9 Offline
                    9500394002
                    wrote on last edited by
                    #10

                    Sorry i could n't noticed that.I will read your suggestion and get back to you if any queries

                    1 Reply Last reply
                    0
                    • 9 9500394002

                      If we create static class , we cannot able to create instance. but ,my query is that instance should be created only one time and restrict to more than one.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      9500394002 wrote:

                      If we create static class , we cannot able to create instance.

                      There's one instance by definition, so no use in creating it.

                      9500394002 wrote:

                      but ,my query is that instance should be created only one time and restrict to more than one.

                      That's exactly what the static class was intended for.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

                      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