Make everything public

I think everything (fields, classes and methods) should be public. Don't shoot me yet there is method to my madness

Consider the following points

  • how many times have you cursed a software vendor or an open source project for not exposing some piece of functionality.
  • anything less than public is not really encapsulation it is just a "keep off my lawn". People can still access things through reflection. Alternatively people can use the big hammer of Mono Cecil and modify a compile assembly to make everything public.
  • hiding things makes extension harder. Many possible extension scenarios are crippled because consumers cannot access the internal workings of our data structures.
  • it is not enough to make things protected. This limits extension points to inheritance and this is not always ideal

How to address the problem of surface area

If everything is public it makes for a very large surface area on the API, essentially polluting the API for standard consumers. With the existing tools suite of .net and Visual Studio it is possible to use the EditorBrowsableAttribute on things that are advanced usage members. Advanced users can then toggle the setting in VS to see the hidden members. This is, of course, not ideal but the best that can be achieved using standard tools.

Posted by: Simon Cropp
Last revised: 20 Dec, 2011 11:00 AM History

Comments

No comments yet. Be the first!

No new comments are allowed on this post.