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. come on give me a break !!

come on give me a break !!

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
14 Posts 10 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.
  • A Ankush Bansal

    He must be sleeping :zzz: while coding :laugh: Explanation: Currently we allow only internal implementation, in future we may allow external as well, so we have interface. Does it make any sense??:confused:

    S Offline
    S Offline
    StM0n
    wrote on last edited by
    #5

    Ankush Bansal wrote:

    Does it make any sense??

    Er... no... but what does :laugh:

    (yes|no|maybe)*

    1 Reply Last reply
    0
    • A Ankush Bansal

      Just saw this: public interface IInterface { //some interface } internal SomeClass : IInterface { } public class PublicAPI { public void PublicFunc(IInterface i) { if(!(i is SomeClass)) { throw new Exception("External implementation of IInterface is not allowed!!"); //what a crap?? } } } why on earth would you expose an interface if you restrict it to one single concrete implementation?:mad:

      R Offline
      R Offline
      Rahul Rajat Singh
      wrote on last edited by
      #6

      Perhaps it is some kind of Monomorphism implementation using interfaces :-)

      J 1 Reply Last reply
      0
      • A Ankush Bansal

        Just saw this: public interface IInterface { //some interface } internal SomeClass : IInterface { } public class PublicAPI { public void PublicFunc(IInterface i) { if(!(i is SomeClass)) { throw new Exception("External implementation of IInterface is not allowed!!"); //what a crap?? } } } why on earth would you expose an interface if you restrict it to one single concrete implementation?:mad:

        B Offline
        B Offline
        BillW33
        wrote on last edited by
        #7

        That is bizarre. I wonder what was going through the original coder’s head? :confused:

        Just because the code works, it doesn't mean that it is good code.

        OriginalGriffO 1 Reply Last reply
        0
        • B BillW33

          That is bizarre. I wonder what was going through the original coder’s head? :confused:

          Just because the code works, it doesn't mean that it is good code.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #8

          His ass?

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          C 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            His ass?

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            C Offline
            C Offline
            cptKoala
            wrote on last edited by
            #9

            Skydiving with a malfunctioning parachute?

            1 Reply Last reply
            0
            • R Rahul Rajat Singh

              Perhaps it is some kind of Monomorphism implementation using interfaces :-)

              J Offline
              J Offline
              Jan Steyn
              wrote on last edited by
              #10

              :^) :doh: :laugh:

              1 Reply Last reply
              0
              • A Ankush Bansal

                Just saw this: public interface IInterface { //some interface } internal SomeClass : IInterface { } public class PublicAPI { public void PublicFunc(IInterface i) { if(!(i is SomeClass)) { throw new Exception("External implementation of IInterface is not allowed!!"); //what a crap?? } } } why on earth would you expose an interface if you restrict it to one single concrete implementation?:mad:

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #11

                One reason I can think of is to reduce the impact of a later change. So, you have IAnimal, implemented by both Duck and Dog. It would be useful to keep collections of IAnimal so you can hold both your Ducks and Dogs and perform IAnimal operations on them. However, suppose you can't get to implementing Dog yet, but you know it will exist in the future. You might code toward a known future objective that doesn't appear to be of any use yet. "Why not make IAnimal an internal class so it isn't visible outside the assembly", you ask. Well, that interface and the classes that implement it may be required in multiple assemblies.

                Thou mewling ill-breeding pignut!

                B A 2 Replies Last reply
                0
                • A AspDotNetDev

                  One reason I can think of is to reduce the impact of a later change. So, you have IAnimal, implemented by both Duck and Dog. It would be useful to keep collections of IAnimal so you can hold both your Ducks and Dogs and perform IAnimal operations on them. However, suppose you can't get to implementing Dog yet, but you know it will exist in the future. You might code toward a known future objective that doesn't appear to be of any use yet. "Why not make IAnimal an internal class so it isn't visible outside the assembly", you ask. Well, that interface and the classes that implement it may be required in multiple assemblies.

                  Thou mewling ill-breeding pignut!

                  B Offline
                  B Offline
                  BillW33
                  wrote on last edited by
                  #12

                  Yeah, that sounds logical. The original coder really should have added comments to explain what he was doing and why. Unfortunately, those kind of comments are all too rare. :sigh:

                  Just because the code works, it doesn't mean that it is good code.

                  1 Reply Last reply
                  0
                  • A AspDotNetDev

                    One reason I can think of is to reduce the impact of a later change. So, you have IAnimal, implemented by both Duck and Dog. It would be useful to keep collections of IAnimal so you can hold both your Ducks and Dogs and perform IAnimal operations on them. However, suppose you can't get to implementing Dog yet, but you know it will exist in the future. You might code toward a known future objective that doesn't appear to be of any use yet. "Why not make IAnimal an internal class so it isn't visible outside the assembly", you ask. Well, that interface and the classes that implement it may be required in multiple assemblies.

                    Thou mewling ill-breeding pignut!

                    A Offline
                    A Offline
                    Ankush Bansal
                    wrote on last edited by
                    #13

                    I think you are missing a point here:rose:. The issue is not that they have exposed an interface say IAnimal and they only have Duck implementation, and Dog's is pending. The issue is they throwing an exception if concrete impl of IAnimal is external (even if its else's Duck). Point being why to create a false API? Why to show that API can handle any IAnimal but would throw if animals are external. :laugh: Why can't an IAnimal be external? why can't someone else's Duck be processed? I personally believe that if any point there is a need of such check then either one should make concrete impl of Duck public and take that as input in func or one can have a public proxy for Duck.

                    P 1 Reply Last reply
                    0
                    • A Ankush Bansal

                      I think you are missing a point here:rose:. The issue is not that they have exposed an interface say IAnimal and they only have Duck implementation, and Dog's is pending. The issue is they throwing an exception if concrete impl of IAnimal is external (even if its else's Duck). Point being why to create a false API? Why to show that API can handle any IAnimal but would throw if animals are external. :laugh: Why can't an IAnimal be external? why can't someone else's Duck be processed? I personally believe that if any point there is a need of such check then either one should make concrete impl of Duck public and take that as input in func or one can have a public proxy for Duck.

                      P Offline
                      P Offline
                      Pascal Ganaye
                      wrote on last edited by
                      #14

                      Being a bit of a devils' advocate here. I think this code definitely require a better message in the exception or description in the code. However Perhaps the programmer want to prevent the class from being inherited. This is why he made it internal. He could have make it public and sealed and as I see it get the same effect. Sometime when you define an api though, it might not be such a bad idea to keep everything in interfaces. This way the library can be modified without impacting the Interfaces that have been exposed previously.

                      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