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. Other Discussions
  3. The Weird and The Wonderful
  4. The Useful DLL

The Useful DLL

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
16 Posts 4 Posters 22 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.
  • V Offline
    V Offline
    VentsyV
    wrote on last edited by
    #1

    public sealed class ClassName: ClassNameBase { //Stuff internal ClassName(Type1 param1, Type2 param2) :base( param1, param2) { } } Whats the beauty of it ?? The class does not have a single static member, and is compiled all by itself to a DLL.

    P 1 Reply Last reply
    0
    • V VentsyV

      public sealed class ClassName: ClassNameBase { //Stuff internal ClassName(Type1 param1, Type2 param2) :base( param1, param2) { } } Whats the beauty of it ?? The class does not have a single static member, and is compiled all by itself to a DLL.

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

      Well - it does provide a concrete implementation of ClassNameBase, so it would work. OK - perhaps ClassNameBase shouldn't be an abstract class (I'm assuming that it is abstract), but this would work.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      V 1 Reply Last reply
      0
      • P Pete OHanlon

        Well - it does provide a concrete implementation of ClassNameBase, so it would work. OK - perhaps ClassNameBase shouldn't be an abstract class (I'm assuming that it is abstract), but this would work.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        V Offline
        V Offline
        VentsyV
        wrote on last edited by
        #3

        Not sure I see your point. The Class is sealed - therefore it can not be inherited. The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either. ClassNameBase has nothing to do with anything at all.

        P L 2 Replies Last reply
        0
        • V VentsyV

          Not sure I see your point. The Class is sealed - therefore it can not be inherited. The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either. ClassNameBase has nothing to do with anything at all.

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

          VentsyV wrote:

          ClassNameBase has nothing to do with anything at all.

          Actually, it does. It's the constructor that has nothing to do with it. You could create this with:

          ClassNameBase myclass = new ClassNameBase();
          ClassName concreteImpl = myClass;
          

          I'm not sure how useful this would be, but it could be done.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          L 1 Reply Last reply
          0
          • V VentsyV

            Not sure I see your point. The Class is sealed - therefore it can not be inherited. The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either. ClassNameBase has nothing to do with anything at all.

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            VentsyV wrote:

            The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either.

            That is correct, but it's likely the library writer wants to expose the instance via a member, but still disallow instantiation. IMO, this shows a very good knowledge of the language/platform being dealt with (unless it really was a mistake!).

            xacc.ide - now with IronScheme support
            IronScheme - 1.0 alpha 2 out now

            P V 2 Replies Last reply
            0
            • P Pete OHanlon

              VentsyV wrote:

              ClassNameBase has nothing to do with anything at all.

              Actually, it does. It's the constructor that has nothing to do with it. You could create this with:

              ClassNameBase myclass = new ClassNameBase();
              ClassName concreteImpl = myClass;
              

              I'm not sure how useful this would be, but it could be done.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              Pete O'Hanlon wrote:

              ClassNameBase myclass = new ClassNameBase();ClassName concreteImpl = myClass; I'm not sure how useful this would be, but it could be done.

              Actually it cant be done :p You would need an implicit cast from a base class to it's parent derivation, and the CLR does not permit that. ;P See my post for the likely explanation why it is sealed with an internal constructor.

              xacc.ide - now with IronScheme support
              IronScheme - 1.0 alpha 2 out now

              P 1 Reply Last reply
              0
              • L leppie

                VentsyV wrote:

                The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either.

                That is correct, but it's likely the library writer wants to expose the instance via a member, but still disallow instantiation. IMO, this shows a very good knowledge of the language/platform being dealt with (unless it really was a mistake!).

                xacc.ide - now with IronScheme support
                IronScheme - 1.0 alpha 2 out now

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

                If the class is laid out without any other members (as in the OP) then this wouldn't be it.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                L 1 Reply Last reply
                0
                • L leppie

                  Pete O'Hanlon wrote:

                  ClassNameBase myclass = new ClassNameBase();ClassName concreteImpl = myClass; I'm not sure how useful this would be, but it could be done.

                  Actually it cant be done :p You would need an implicit cast from a base class to it's parent derivation, and the CLR does not permit that. ;P See my post for the likely explanation why it is sealed with an internal constructor.

                  xacc.ide - now with IronScheme support
                  IronScheme - 1.0 alpha 2 out now

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

                  You're right of course. How could I have missed that? A 5 for spotting my stupidity.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  1 Reply Last reply
                  0
                  • P Pete OHanlon

                    If the class is laid out without any other members (as in the OP) then this wouldn't be it.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    Pete O'Hanlon wrote:

                    If the class is laid out without any other members (as in the OP) then this wouldn't be it.

                    You missed the '//Stuff' bit? ;P

                    xacc.ide - now with IronScheme support
                    IronScheme - 1.0 alpha 2 out now

                    P 1 Reply Last reply
                    0
                    • L leppie

                      Pete O'Hanlon wrote:

                      If the class is laid out without any other members (as in the OP) then this wouldn't be it.

                      You missed the '//Stuff' bit? ;P

                      xacc.ide - now with IronScheme support
                      IronScheme - 1.0 alpha 2 out now

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

                      Damn - I did :doh: . If I'd seen that, I'd have answered the same as you - I guess I have "stuff" blindness (I'd normally put this in as // Do Something here).

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      1 Reply Last reply
                      0
                      • L leppie

                        VentsyV wrote:

                        The constructor is internal and the class is in a DLL, therefore you can't create an instance of the class either.

                        That is correct, but it's likely the library writer wants to expose the instance via a member, but still disallow instantiation. IMO, this shows a very good knowledge of the language/platform being dealt with (unless it really was a mistake!).

                        xacc.ide - now with IronScheme support
                        IronScheme - 1.0 alpha 2 out now

                        V Offline
                        V Offline
                        VentsyV
                        wrote on last edited by
                        #11

                        leppie wrote:

                        That is correct, but it's likely the library writer wants to expose the instance via a member, but still disallow instantiation

                        Can you explain this ?? I can't make sense out of it. What instance ?? There is no way you can create any instance of this class, as it is in assembly by itself.

                        L 1 Reply Last reply
                        0
                        • V VentsyV

                          leppie wrote:

                          That is correct, but it's likely the library writer wants to expose the instance via a member, but still disallow instantiation

                          Can you explain this ?? I can't make sense out of it. What instance ?? There is no way you can create any instance of this class, as it is in assembly by itself.

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #12

                          VentsyV wrote:

                          There is no way you can create any instance of this class, as it is in assembly by itself.

                          First off, if this class in an assembly by itself and the assembly does not have any friend assemblies, the rest that follow is irrelevant. Then it means he uses reflection for something stupid. You need to understand that you dont need to create an instance. Lets take a 'real world' example (this is in xacc.ide, not sure how real world it is ;P ):

                          public sealed class TextBuffer
                          {
                          internal TextBuffer(AdvancedTextBox atb) { ... }
                          }

                          public class AdvancedTextBox
                          {
                          public TextBuffer Buffer {get {return buffer;}}
                          public AdvancedTextBox()
                          {
                          buffer = new TextBuffer(this);
                          }
                          }

                          Now I dont want anyone to use the TextBuffer class without using my AdvancedTextBox class. In other words, the author states the class is not usable without accessing it thought an AdvancedTextBox instance, for whatever reason that may be (perhaps unstable, restricted, propriety, etc). Note: the example is not exactly like it is in xacc.ide, I rather use the better approach of making TextBuffer a nested class of AdvancedTextBox, thus giving me even more flexibility on usage. ;)

                          xacc.ide - now with IronScheme support
                          IronScheme - 1.0 alpha 2 out now

                          P V 2 Replies Last reply
                          0
                          • L leppie

                            VentsyV wrote:

                            There is no way you can create any instance of this class, as it is in assembly by itself.

                            First off, if this class in an assembly by itself and the assembly does not have any friend assemblies, the rest that follow is irrelevant. Then it means he uses reflection for something stupid. You need to understand that you dont need to create an instance. Lets take a 'real world' example (this is in xacc.ide, not sure how real world it is ;P ):

                            public sealed class TextBuffer
                            {
                            internal TextBuffer(AdvancedTextBox atb) { ... }
                            }

                            public class AdvancedTextBox
                            {
                            public TextBuffer Buffer {get {return buffer;}}
                            public AdvancedTextBox()
                            {
                            buffer = new TextBuffer(this);
                            }
                            }

                            Now I dont want anyone to use the TextBuffer class without using my AdvancedTextBox class. In other words, the author states the class is not usable without accessing it thought an AdvancedTextBox instance, for whatever reason that may be (perhaps unstable, restricted, propriety, etc). Note: the example is not exactly like it is in xacc.ide, I rather use the better approach of making TextBuffer a nested class of AdvancedTextBox, thus giving me even more flexibility on usage. ;)

                            xacc.ide - now with IronScheme support
                            IronScheme - 1.0 alpha 2 out now

                            P Offline
                            P Offline
                            PIEBALDconsult
                            wrote on last edited by
                            #13

                            Might there be a factory method?

                            L 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              Might there be a factory method?

                              L Offline
                              L Offline
                              leppie
                              wrote on last edited by
                              #14

                              No, he states that there are no static members.

                              xacc.ide - now with IronScheme support
                              IronScheme - 1.0 alpha 2 out now

                              P 1 Reply Last reply
                              0
                              • L leppie

                                No, he states that there are no static members.

                                xacc.ide - now with IronScheme support
                                IronScheme - 1.0 alpha 2 out now

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #15

                                Oh, yeah, I knew that... :doh:

                                1 Reply Last reply
                                0
                                • L leppie

                                  VentsyV wrote:

                                  There is no way you can create any instance of this class, as it is in assembly by itself.

                                  First off, if this class in an assembly by itself and the assembly does not have any friend assemblies, the rest that follow is irrelevant. Then it means he uses reflection for something stupid. You need to understand that you dont need to create an instance. Lets take a 'real world' example (this is in xacc.ide, not sure how real world it is ;P ):

                                  public sealed class TextBuffer
                                  {
                                  internal TextBuffer(AdvancedTextBox atb) { ... }
                                  }

                                  public class AdvancedTextBox
                                  {
                                  public TextBuffer Buffer {get {return buffer;}}
                                  public AdvancedTextBox()
                                  {
                                  buffer = new TextBuffer(this);
                                  }
                                  }

                                  Now I dont want anyone to use the TextBuffer class without using my AdvancedTextBox class. In other words, the author states the class is not usable without accessing it thought an AdvancedTextBox instance, for whatever reason that may be (perhaps unstable, restricted, propriety, etc). Note: the example is not exactly like it is in xacc.ide, I rather use the better approach of making TextBuffer a nested class of AdvancedTextBox, thus giving me even more flexibility on usage. ;)

                                  xacc.ide - now with IronScheme support
                                  IronScheme - 1.0 alpha 2 out now

                                  V Offline
                                  V Offline
                                  VentsyV
                                  wrote on last edited by
                                  #16

                                  Thats exactly what I've been saying all along. The class is in assembly by itself and there are no friend assemblies declared. There are no static members either. I'm not an expert in C# but to me that makes no sense whatsoever. Also, in the example you gave, you did create an instance of TextBuffer, and by the way, you have to declare buffer (lowercase 'b') somewhere or you'll get a compiler error.

                                  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