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. New trend at work...

New trend at work...

Scheduled Pinned Locked Moved The Weird and The Wonderful
cssregexhelpquestion
7 Posts 3 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.
  • Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #1

    Less code is better... This week I made some ManagerClass that keeps track of a Dictionary(Of String, IMyInterface) There are Add and Remove Methods(ByVal s As String, ByVal myInterface As IMyInterface) in the ManagerClass that simply add or remove items from the dictionary if the dictionary does not already have them... So now my boss wanted that the Dictionary(Of String, IMyInterface) could contain List(Of IMyInterface) instead of just the IMyInterface Well, shiver me timbers! Luckily I have recently read about OOP and applied it here. I created a ListInterfaceClass that Implemented IMyInterface and made it so that it keeps a list. Problem solved (really, does everything it should). However, when using these Classes you should first instantiate a New ListInterfaceClass, add IMyInterface items to it and then add it to the ManagerClass. If you really wanted to pass it a list of those interfaces that is... Maybe you want to pass it a single interface class. So both options are open, and any extension of IMyInterface could still be added. On a side note: I think I am really getting the hang of OOD! Perhaps some of you are recognizing the Chain Of Command Pattern? :) So I showed what I had made to my boss, but he thought that instantiating a New ListInterfaceClass was too much work and the ManagerClass should do it for you. Results: -The MangerClass is now limited to managing ListInterfaceClass only. -Any extensions or surrogates for the ListInterfaceClass are not possible. -The ManagerClass is now responsible for putting any IMyInterface it gets into a ListInterfaceClass (and checking if it already exists etc.). -If for any reason the ListInterfaceClass would not suffice anymore I would have to rewrite the ManagerClass directly. BUT! We do possibly save two lines of code when using the ManagerClass :thumbsup: This is my second well-designed class structure (I think/hope) and this is the second time I had to throw it overboard because "the user of the classes has to write too much code." The users being my bosses and co-workers. This company trend is making me worry... :~

    It's an OO world.

    L 1 Reply Last reply
    0
    • Sander RosselS Sander Rossel

      Less code is better... This week I made some ManagerClass that keeps track of a Dictionary(Of String, IMyInterface) There are Add and Remove Methods(ByVal s As String, ByVal myInterface As IMyInterface) in the ManagerClass that simply add or remove items from the dictionary if the dictionary does not already have them... So now my boss wanted that the Dictionary(Of String, IMyInterface) could contain List(Of IMyInterface) instead of just the IMyInterface Well, shiver me timbers! Luckily I have recently read about OOP and applied it here. I created a ListInterfaceClass that Implemented IMyInterface and made it so that it keeps a list. Problem solved (really, does everything it should). However, when using these Classes you should first instantiate a New ListInterfaceClass, add IMyInterface items to it and then add it to the ManagerClass. If you really wanted to pass it a list of those interfaces that is... Maybe you want to pass it a single interface class. So both options are open, and any extension of IMyInterface could still be added. On a side note: I think I am really getting the hang of OOD! Perhaps some of you are recognizing the Chain Of Command Pattern? :) So I showed what I had made to my boss, but he thought that instantiating a New ListInterfaceClass was too much work and the ManagerClass should do it for you. Results: -The MangerClass is now limited to managing ListInterfaceClass only. -Any extensions or surrogates for the ListInterfaceClass are not possible. -The ManagerClass is now responsible for putting any IMyInterface it gets into a ListInterfaceClass (and checking if it already exists etc.). -If for any reason the ListInterfaceClass would not suffice anymore I would have to rewrite the ManagerClass directly. BUT! We do possibly save two lines of code when using the ManagerClass :thumbsup: This is my second well-designed class structure (I think/hope) and this is the second time I had to throw it overboard because "the user of the classes has to write too much code." The users being my bosses and co-workers. This company trend is making me worry... :~

      It's an OO world.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      well, I would agree classes first of all should be easy to use, rather than easy to design and implement. The whole idea is to encapsulate the petty details so the user hasn't to worry about them. :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      Sander RosselS 1 Reply Last reply
      0
      • L Luc Pattyn

        well, I would agree classes first of all should be easy to use, rather than easy to design and implement. The whole idea is to encapsulate the petty details so the user hasn't to worry about them. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        Sander RosselS Offline
        Sander RosselS Offline
        Sander Rossel
        wrote on last edited by
        #3

        Well, the implementation now looks like this...

        ' This is 16 words and 200 characters.
        ' Most of this is IntelliSense.
        Dim list As New ListInterfaceClass
        list.AddToList(New Example1)
        list.AddToList(New Example2)
        list.AddToList(New Example3)

        manager.AddToManager("String1", list)
        manager.AddToManager("String2", New Example4)

        The problem here is that I cannot add "String1" to the ManagerClass twice. It should look like this according to my boss...

        ' This is 12 words and 180 characters.
        ' None of the string have IntelliSense.
        manager.AddToManager("String1", New Example1)
        manager.AddToManager("String1", New Example2)
        manager.AddToManager("String1", New Example3)
        manager.AddToManager("String2", New Example4)

        Really, how much work does this save the user? 4 words or 20 characters? Most is IntelliSence and if the list gets bigger it actually has less characters! ;) More importantly, to get the result my boss wants I should have the ManagerClass depend on the ListInterfaceClass while they are now completely ignorant of each other. Microsoft did not put its Connection, Command and Adapter Classes into one Class to make it easier for the user either, did they? Perhaps ORM tools do something like that, but if that is how it is done then I guess I should also make some wrapper ListManagerClass to encapsulate the ManagerClass and ListInterfaceClass rather than changing the current ManagerClass :) P.S. I did not really name my classes 'ManagerClass' and 'ListInterfaceClass', that WOULD make it hard on the user... :laugh:

        It's an OO world.

        L 1 Reply Last reply
        0
        • Sander RosselS Sander Rossel

          Well, the implementation now looks like this...

          ' This is 16 words and 200 characters.
          ' Most of this is IntelliSense.
          Dim list As New ListInterfaceClass
          list.AddToList(New Example1)
          list.AddToList(New Example2)
          list.AddToList(New Example3)

          manager.AddToManager("String1", list)
          manager.AddToManager("String2", New Example4)

          The problem here is that I cannot add "String1" to the ManagerClass twice. It should look like this according to my boss...

          ' This is 12 words and 180 characters.
          ' None of the string have IntelliSense.
          manager.AddToManager("String1", New Example1)
          manager.AddToManager("String1", New Example2)
          manager.AddToManager("String1", New Example3)
          manager.AddToManager("String2", New Example4)

          Really, how much work does this save the user? 4 words or 20 characters? Most is IntelliSence and if the list gets bigger it actually has less characters! ;) More importantly, to get the result my boss wants I should have the ManagerClass depend on the ListInterfaceClass while they are now completely ignorant of each other. Microsoft did not put its Connection, Command and Adapter Classes into one Class to make it easier for the user either, did they? Perhaps ORM tools do something like that, but if that is how it is done then I guess I should also make some wrapper ListManagerClass to encapsulate the ManagerClass and ListInterfaceClass rather than changing the current ManagerClass :) P.S. I did not really name my classes 'ManagerClass' and 'ListInterfaceClass', that WOULD make it hard on the user... :laugh:

          It's an OO world.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I see. There isn't that much of a difference from the caller's point of view after all. You could take advantage of the params keyword, and accept the following:

          manager.AddToManager("String1", New ListInterfaceClass(New Example1, New Example2, New Example3))
          manager.AddToManager("String2", New Example4)

          or

          manager.AddToManager("String1", New Example1, New Example2, New Example3)
          manager.AddToManager("String2", New Example4)

          I might go for the latter. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          Sander RosselS 1 Reply Last reply
          0
          • L Luc Pattyn

            I see. There isn't that much of a difference from the caller's point of view after all. You could take advantage of the params keyword, and accept the following:

            manager.AddToManager("String1", New ListInterfaceClass(New Example1, New Example2, New Example3))
            manager.AddToManager("String2", New Example4)

            or

            manager.AddToManager("String1", New Example1, New Example2, New Example3)
            manager.AddToManager("String2", New Example4)

            I might go for the latter. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #5

            That is not a bad idea at all! Of course it would be:

            manager.AddToManager("String1", New ListInterfaceClass({New Example1, New Example2, New Example3}))

            Your second option would once again require a dependency between ManagerClass and ListInterfaceClass. It is probably going to be like that anyway, because my boss wants it, but that would result in having to rewrite or at least recheck the ManagerClass once the ListInterfaceClass changes or is made obsolete. And that happens a lot in our company... Besides, I recently showed something like that to my boss:

            Dim something as New Class4(New Class3(New Class2(New Class1)))

            His reply was "This looks really weird, did you just make that up? In all my seven years of experience I have never ever seen anything like that and Microsoft does not do that for sure!" then he started yelling and saying "You read some articles on the internet and think you know it all, but I have seven years of experience! You have obviously not understood anything if you make code like that!" I was speechless.... Maybe I posted this thread in the wrong forum. Although the 'less code is better' mentality is still something to be ashamed off. At least the way it is currently implemented (I know of a much worse example, but that would be to much to type here) ;)

            It's an OO world.

            T 1 Reply Last reply
            0
            • Sander RosselS Sander Rossel

              That is not a bad idea at all! Of course it would be:

              manager.AddToManager("String1", New ListInterfaceClass({New Example1, New Example2, New Example3}))

              Your second option would once again require a dependency between ManagerClass and ListInterfaceClass. It is probably going to be like that anyway, because my boss wants it, but that would result in having to rewrite or at least recheck the ManagerClass once the ListInterfaceClass changes or is made obsolete. And that happens a lot in our company... Besides, I recently showed something like that to my boss:

              Dim something as New Class4(New Class3(New Class2(New Class1)))

              His reply was "This looks really weird, did you just make that up? In all my seven years of experience I have never ever seen anything like that and Microsoft does not do that for sure!" then he started yelling and saying "You read some articles on the internet and think you know it all, but I have seven years of experience! You have obviously not understood anything if you make code like that!" I was speechless.... Maybe I posted this thread in the wrong forum. Although the 'less code is better' mentality is still something to be ashamed off. At least the way it is currently implemented (I know of a much worse example, but that would be to much to type here) ;)

              It's an OO world.

              T Offline
              T Offline
              TorstenFrings
              wrote on last edited by
              #6

              Naerling wrote:

              Of course it would be:

              manager.AddToManager("String1", New ListInterfaceClass({New Example1, New Example2, New Example3}))

              have you looked at the ParamArray keyword? It allows you to declare a function that takes a variable number of parameters and handles them as an array... so you don't need no curly braces

              Sander RosselS 1 Reply Last reply
              0
              • T TorstenFrings

                Naerling wrote:

                Of course it would be:

                manager.AddToManager("String1", New ListInterfaceClass({New Example1, New Example2, New Example3}))

                have you looked at the ParamArray keyword? It allows you to declare a function that takes a variable number of parameters and handles them as an array... so you don't need no curly braces

                Sander RosselS Offline
                Sander RosselS Offline
                Sander Rossel
                wrote on last edited by
                #7

                That is pretty nice! :D Although ParamArray is still not what my boss wants. Simply passing Classes as parameters all of a sudden seems not done anymore :???: My boss says it is to confusing for new developers. He now wants to change the above code alltogether, making it Generic and creating the Class that should be added using Reflection. Code would look like:

                manager.AddToManager(Of ListInterfaceClass)("String1") ' The AddToManager Method would create a new instance of ListInterfaceClass.

                According to him this is much more readable than:

                manager.AddToManager("String1", New ListInterfaceClass)

                I don't think anything can save me anymore, not even ParamArray X|

                It's an OO world.

                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