New trend at work...
-
Less code is better... This week I made some
ManagerClass
that keeps track of aDictionary(Of String, IMyInterface)
There are Add and RemoveMethods(ByVal s As String, ByVal myInterface As IMyInterface)
in theManagerClass
that simply add or remove items from the dictionary if the dictionary does not already have them... So now my boss wanted that theDictionary(Of String, IMyInterface)
could containList(Of IMyInterface)
instead of just theIMyInterface
Well, shiver me timbers! Luckily I have recently read about OOP and applied it here. I created aListInterfaceClass
thatImplemented 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 aNew ListInterfaceClass
, addIMyInterface
items to it and then add it to theManagerClass
. 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 ofIMyInterface
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 aNew ListInterfaceClass
was too much work and theManagerClass
should do it for you. Results: -TheMangerClass
is now limited to managingListInterfaceClass
only. -Any extensions or surrogates for theListInterfaceClass
are not possible. -TheManagerClass
is now responsible for putting anyIMyInterface
it gets into aListInterfaceClass
(and checking if it already exists etc.). -If for any reason theListInterfaceClass
would not suffice anymore I would have to rewrite theManagerClass
directly. BUT! We do possibly save two lines of code when using theManagerClass
: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.
-
Less code is better... This week I made some
ManagerClass
that keeps track of aDictionary(Of String, IMyInterface)
There are Add and RemoveMethods(ByVal s As String, ByVal myInterface As IMyInterface)
in theManagerClass
that simply add or remove items from the dictionary if the dictionary does not already have them... So now my boss wanted that theDictionary(Of String, IMyInterface)
could containList(Of IMyInterface)
instead of just theIMyInterface
Well, shiver me timbers! Luckily I have recently read about OOP and applied it here. I created aListInterfaceClass
thatImplemented 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 aNew ListInterfaceClass
, addIMyInterface
items to it and then add it to theManagerClass
. 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 ofIMyInterface
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 aNew ListInterfaceClass
was too much work and theManagerClass
should do it for you. Results: -TheMangerClass
is now limited to managingListInterfaceClass
only. -Any extensions or surrogates for theListInterfaceClass
are not possible. -TheManagerClass
is now responsible for putting anyIMyInterface
it gets into aListInterfaceClass
(and checking if it already exists etc.). -If for any reason theListInterfaceClass
would not suffice anymore I would have to rewrite theManagerClass
directly. BUT! We do possibly save two lines of code when using theManagerClass
: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.
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.
-
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.
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 theListInterfaceClass
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 wrapperListManagerClass
to encapsulate theManagerClass
andListInterfaceClass
rather than changing the currentManagerClass
:) 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.
-
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 theListInterfaceClass
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 wrapperListManagerClass
to encapsulate theManagerClass
andListInterfaceClass
rather than changing the currentManagerClass
:) 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.
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.
-
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.
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
andListInterfaceClass
. 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 theManagerClass
once theListInterfaceClass
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.
-
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
andListInterfaceClass
. 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 theManagerClass
once theListInterfaceClass
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.
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 -
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 bracesThat 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.