Pattern for forcing adding to collection through method in C# -


I have a class with a collection member. I would like to prevent external code from modifying this collection directly, instead use methods (which can do proper verification etc.).

I thought it was tough. Here's the solution I'm using Can you please tell me if it's the best way to do common practice? All this seems just a little ovenenariad.

  By using the system. Colllections.Generic; Using System.Collections.ObjectModel; Public Sector Fu {Private list & lt; Bars & gt; _bars = new list & lt; Bars & gt; (); Public readline calling & lt; Bars & gt; Bar ({return _bars.AsReadOnly ();}} Public Zero AdBar (repeatedly) // Black Sheep {// Insert Validation logic here _bar. (Bar);}}  

I think this is a good solution, this approach has been discussed here by Martin Fowler


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -