Replies: 1 comment 1 reply
-
Using static methods makes it very difficult to unit test codes that uses those methods, because you can't mock them. For example, let's say my extension should show the progress of some operation in the status bar. If I want to verify that my extension is displaying the progress correctly, I could mock the If the Related discussion about using interfaces for major types: #85 |
Beta Was this translation helpful? Give feedback.
-
Update: There was some input regarding static methods and probably not the best approach, so disregard thoughts specific to static.
This discussion attempts to point out a few areas related to current namespaces and classes. Understanding there have been similar discussions previously, but IMHO wanted to try and combine a few notes to hopefully improve the toolkit.
While having the
VS
class simplifies ease of access, it seems like the APIs could be improved by updating the namespaces and changing most of the sections to use static methods (where applicable). Below uses theStatusBar
as an example, but is also relevant to others likeSolutions
,Documents
, etc.More Detailed Namespaces
First, the namespace should follow a similar path where located in folder structure (at least in most cases). This helps separate out the sections instead of dumping everything within
Community.VisualStudio.Toolkit
. It will get messy fast as you can already see by using IntelliSense with the toolkit.For
StatusBar
, its namespace should beCommunity.VisualStudio.Toolkit.Notifications
since it is located in the Notifications folder. It would look like the following as a result:Improved Class Naming
There have been some earlier discussions on naming of various toolkit classes. I still believe it would be appropriate to rename
StatusBar
toStatusBarNotification
even if it is within theCommunity.VisualStudio.Toolkit.Notifications
namespace. I agree it is somewhat redundant, but will not appear that way when using ausing statement
and having the class name by itself. UseSyntax
from the Roslyn repo as example where they have "Syntax" in the name.It would look similar to the following as a result:
Changing to Static Class Methods
All methods currently in the
StatusBar
class can be changed to static as it doesn't include anything needed to instantiate the object first. As an example, you would have the following static method:Combining Points Above
Combining the changes above can simplify the toolkit for readability, usage, and maintenance. As an example, you don't necessarily have to use the
VS
class.Final Thoughts
Of course, these are just my simple opinions. These suggestions are not specific to the current
VS
class (just used as an example), but more about improving the overall structure of the toolkit's APIs. As noted, the example changes for theStatusBar
class could also be applied to other areas likeInfoBar
,Documents
, andSolutions
. Any feedback/thoughts are appreciated in this collaborative effort. I don't mind attempting a PR if the above seems like a good approach. Thanks for reading.Beta Was this translation helpful? Give feedback.
All reactions