<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx</link><description>Here is a minor update to the design guidelines around subclassing. It is based on this quiz I did a last week . Please let me know if you have any questions or comments. As always, you can check out the base design guidelines and my incremental updates.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#227356</link><pubDate>Thu, 09 Sep 2004 14:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227356</guid><dc:creator>Jeroen Frijters</dc:creator><description>This is one of those &amp;quot;I got carried away&amp;quot; nonsense guidelines. There is nothing wrong with protected statics, you just have to know what you're doing. The example is obviously stupid, but that doesn't mean you should never use protected statics.</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#227373</link><pubDate>Thu, 09 Sep 2004 14:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227373</guid><dc:creator>Brad Abrams [MSFT]</dc:creator><description>OK -- I am game... what do you think is a good use of protected statics?  </description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#227417</link><pubDate>Thu, 09 Sep 2004 16:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227417</guid><dc:creator>Nathan Neitzke</dc:creator><description>I have a comment about your example.  It is with the annotation that instanced data could not be accessed.&lt;br&gt;&lt;br&gt;What if Malicious inherited from Child?  Would it then succeed even in the CLR?&lt;br&gt;&lt;br&gt;Thanks.</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#227455</link><pubDate>Thu, 09 Sep 2004 17:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227455</guid><dc:creator>Joe</dc:creator><description>I agree with Jeroen.&lt;br&gt;&lt;br&gt;&amp;quot;protected static&amp;quot; means you explicitly want all subclasses to be able to access the value.  Of course a subclass should and would not store its own sensitive data in a protected static property.&lt;br&gt;&lt;br&gt;As for a use of &amp;quot;protected static&amp;quot;, the most obvious thing would be a readonly value supplied by a base class and used by all subclasses, such as configuration data.&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#227570</link><pubDate>Thu, 09 Sep 2004 20:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:227570</guid><dc:creator>Nicholas Allen</dc:creator><description>I've never actually seen this problem Brad describes in real world code.  What I have seen several times though is a field that is protected, static, but not read only.  The field is usually then written to by several subclasses with the obvious, sometimes fatal, result.&lt;br&gt;&lt;br&gt;I use protected statics quite a bit, primarily to keep the namespace clean.  I don't care if someone gets access; I just want to improve the API usability by not publishing to the documentation, code editors, or a reader some elements that they don't need to think about when using the class.  This gives a clear separation about what's important to external users as opposed to extenders.</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#228006</link><pubDate>Fri, 10 Sep 2004 18:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:228006</guid><dc:creator>Steven Padfield</dc:creator><description>&amp;gt; OK -- I am game... what do you think is a good use of protected statics? &lt;br&gt;&amp;gt; 9/9/2004 7:59 AM | Brad Abrams [MSFT] &lt;br&gt;&lt;br&gt;Personally, I agree with Brad.  I've never used protected statics and I probably never will.  And if I ever see them in someone's code, I'll immediately begin thinking about how to refactor them away.  If Microsoft chooses to remove them from the CLS, I probably won't miss them.&lt;br&gt;&lt;br&gt;If you have to provide subclass access to a private static, provide a protected instance accessor.</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#228014</link><pubDate>Fri, 10 Sep 2004 19:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:228014</guid><dc:creator>Jeroen Frijters</dc:creator><description>My response was a little knee-jerk, because design guidelines are no substitute for actually knowing what you're doing. I feel that anybody that doesn't understand that the code in the example is a bad idea really has no business writing code, but I'm a bit of a snob that way ;-)&lt;br&gt;&lt;br&gt;As to practical use for protected static, I was thinking of readonly fields (constants that aren't primitive, or maybe you don't want the versioning semantics of constants) that are only useful for subclasses.&lt;br&gt;&lt;br&gt;As to examples, just search the BCL:&lt;br&gt;mscorlib:&lt;br&gt;System.Threading.WaitHandle::InvalidHandle&lt;br&gt;System.Security.Util.SiteString::m_separators&lt;br&gt;System.Security.Util.StringExpressionSet::m_emptyList&lt;br&gt;System.Security.Util.StringExpressionSet::m_separators&lt;br&gt;System.Security.Util.StringExpressionSet::m_trimChars&lt;br&gt;System.Security.Util.StringExpressionSet::m_directorySeparator&lt;br&gt;System.Security.Util.StringExpressionSet::m_alternateDirectorySeparator&lt;br&gt;System.Security.Util.DirectoryString::m_illegalDirectoryCharacters&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_DISCONNECTED_FULL&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_DISCONNECTED_REM&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_IN_IDTABLE&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_CONTEXT_BOUND&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_WELLKNOWN&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_SERVER_SINGLECALL&lt;br&gt;System.Runtime.Remoting.Identity::IDFLG_SERVER_SINGLETON&lt;br&gt;&lt;br&gt;System.Windows.Forms:&lt;br&gt;System.Windows.Forms.ScrollableControl::ScrollStateAutoScrolling&lt;br&gt;System.Windows.Forms.ScrollableControl::ScrollStateHScrollVisible&lt;br&gt;System.Windows.Forms.ScrollableControl::ScrollStateVScrollVisible&lt;br&gt;System.Windows.Forms.ScrollableControl::ScrollStateUserHasScrolled&lt;br&gt;System.Windows.Forms.ScrollableControl::ScrollStateFullDrag&lt;br&gt;System.Windows.Forms.DataGridRow::xOffset&lt;br&gt;System.Windows.Forms.DataGridRow::yOffset&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTitleBackColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTitleForeColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultMonthBackColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTrailingForeColor&lt;br&gt;System.Windows.Forms.FileDialog::EventFileOk&lt;br&gt;System.Windows.Forms.FontDialog::EventApply&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::InvalidPoint&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::DisplayNameComparer&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::NOTIFY_RESET&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::NOTIFY_CAN_RESET&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::NOTIFY_DBL_CLICK&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::NOTIFY_SHOULD_PERSIST&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::NOTIFY_RETURN&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::OUTLINE_ICON_PADDING&lt;br&gt;System.Windows.Forms.PropertyGridInternal.DocComment::CBORDER&lt;br&gt;System.Windows.Forms.PropertyGridInternal.DocComment::CXDEF&lt;br&gt;System.Windows.Forms.PropertyGridInternal.DocComment::CYDEF&lt;br&gt;System.Windows.Forms.PropertyGridInternal.DocComment::MIN_LINES&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridCommands::wfcMenuGroup&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridCommands::wfcMenuCommand&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::InvalidPoint&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::InvalidPosition&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::EDIT_INDENT&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::OUTLINE_INDENT&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::OUTLINE_SIZE&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::PAINT_WIDTH&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::PAINT_INDENT&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::ROWLABEL&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::ROWVALUE&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::MAX_LISTBOX_HEIGHT&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::ERROR_NONE&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::ERROR_THROWN&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::ERROR_MSGBOX_UP&lt;br&gt;System.Windows.Forms.ComponentModel.Com2Interop.Com2IDispatchConverter::none</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#228017</link><pubDate>Fri, 10 Sep 2004 19:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:228017</guid><dc:creator>Jeroen Frijters</dc:creator><description>Oops. Some of those are actually constants.&lt;br&gt;&lt;br&gt;Here is the correct list:&lt;br&gt;mscorlib:&lt;br&gt;System.Threading.WaitHandle::InvalidHandle&lt;br&gt;System.Security.Util.SiteString::m_separators&lt;br&gt;System.Security.Util.StringExpressionSet::m_emptyList&lt;br&gt;System.Security.Util.StringExpressionSet::m_separators&lt;br&gt;System.Security.Util.StringExpressionSet::m_trimChars&lt;br&gt;System.Security.Util.StringExpressionSet::m_directorySeparator&lt;br&gt;System.Security.Util.StringExpressionSet::m_alternateDirectorySeparator&lt;br&gt;System.Security.Util.DirectoryString::m_illegalDirectoryCharacters&lt;br&gt;&lt;br&gt;System.Windows.Forms:&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTitleBackColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTitleForeColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultMonthBackColor&lt;br&gt;System.Windows.Forms.DateTimePicker::DefaultTrailingForeColor&lt;br&gt;System.Windows.Forms.FileDialog::EventFileOk&lt;br&gt;System.Windows.Forms.FontDialog::EventApply&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::InvalidPoint&lt;br&gt;System.Windows.Forms.PropertyGridInternal.GridEntry::DisplayNameComparer&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridCommands::wfcMenuGroup&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridCommands::wfcMenuCommand&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::InvalidPoint&lt;br&gt;System.Windows.Forms.PropertyGridInternal.PropertyGridView::InvalidPosition&lt;br&gt;System.Windows.Forms.ComponentModel.Com2Interop.Com2IDispatchConverter::none</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#228158</link><pubDate>Sat, 11 Sep 2004 01:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:228158</guid><dc:creator>Keith Patrick</dc:creator><description>Does this apply exclusively to protected static properties/fields, or does it go for methods as well?  If I have a method that doesn't use instance data, even protected, I'll often just tack a static to it, but should I not be doing this for some reason?</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229096</link><pubDate>Tue, 14 Sep 2004 00:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229096</guid><dc:creator>Steven Padfield</dc:creator><description>Actually, I just found myself using a protected static method today.&lt;br&gt;&lt;br&gt;Originally, I had a class with a private static method.  Then I had to refactor this into two separate subclasses with a common base abstract class.  Yet both subclasses still needed access to that private static method.  Here were my choices:&lt;br&gt;&lt;br&gt;1) Make the method public static.  This violates encapsulation.&lt;br&gt;&lt;br&gt;2) Copy the method to each of the subclasses.  This results in duplicated code.&lt;br&gt;&lt;br&gt;3) Make the method a protected instance method.  Since the method uses no instance data, does not employ polymorphism, and conceptually has no relationship to specific instances of the class, this is a bad idea and could lead to confusion later.&lt;br&gt;&lt;br&gt;4) Make the method protected static.  This is the decision I made, because it avoids the previous three pitfalls.&lt;br&gt;&lt;br&gt;Maybe the guideline would be better restated as &amp;quot;Avoid Protected Static FIELDS&amp;quot;.&lt;br&gt;&lt;br&gt;Just my $0.02.</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229146</link><pubDate>Tue, 14 Sep 2004 01:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229146</guid><dc:creator>Eric Newton</dc:creator><description>Another irritation:&lt;br&gt;&lt;br&gt;internal protected modifiers dont do what you'd expect... the internal keyword takes precedence over the protected modifier, even though you might need for a subclass to be able to call, but you'd like to give the assembly a way to call into it as well...&lt;br&gt;&lt;br&gt;for example:&lt;br&gt;&amp;lt;code&amp;gt;&lt;br&gt;public class Order&lt;br&gt;{&lt;br&gt;   private int _orderId; //orderId should never be settable from outside the assembly&lt;br&gt;   //but what if somebody subclasses the Order?  It would be nice to let the subclass&lt;br&gt;   //be able to set it... AND let the data classes be able to set it when&lt;br&gt;   // Loading an order or Creating a new order [linking the instance to a record in the db&lt;br&gt;   &lt;br&gt;   public int OrderId&lt;br&gt;   { get { return this._orderId; } }&lt;br&gt;   internal protected void Set_OrderId(int value) { this._orderId=value; }&lt;br&gt;&lt;br&gt;}&lt;br&gt;public class MyOrders  //class handles database interaction&lt;br&gt;{&lt;br&gt;   public MyOrder LoadMyOrder(int orderId)&lt;br&gt;   {&lt;br&gt;       MyOrder o = new MyOrder();&lt;br&gt;       // build a dbcommand to read a record into a datareader&lt;br&gt;       o.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //impossible to do this without making OrderId public somehow&lt;br&gt;   }&lt;br&gt;   ///&amp;lt;summary&amp;gt;Inserts the order into the db&amp;lt;/summary&amp;gt;&lt;br&gt;   ///&amp;lt;returns&amp;gt;the id of the new order. (OrderId property is also set.)&amp;lt;/returns&amp;gt;&lt;br&gt;   public int Insert(MyOrder order)&lt;br&gt;   {&lt;br&gt;       //build a dbcommand to insert the order into the database...&lt;br&gt;       //set the OrderId to the new record?&lt;br&gt;       order.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //another impossible call&lt;br&gt;       return order.OrderId;&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&amp;lt;/code&amp;gt;&lt;br&gt;---------------------------&lt;br&gt;make a new project, referencing the above assembly&lt;br&gt;&lt;br&gt;&amp;lt;code&amp;gt;&lt;br&gt;public class MyOrder : Order&lt;br&gt;{&lt;br&gt;    public DateTime MyOrderSpecificProperty { get; set; }&lt;br&gt;    &lt;br&gt;}&lt;br&gt;public class MyOrders  //class handles database interaction&lt;br&gt;{&lt;br&gt;   public MyOrder LoadMyOrder(int orderId)&lt;br&gt;   {&lt;br&gt;       MyOrder o = new MyOrder();&lt;br&gt;       // build a dbcommand to read a record into a datareader&lt;br&gt;       o.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //impossible to do this without making OrderId public somehow&lt;br&gt;   }&lt;br&gt;   ///&amp;lt;summary&amp;gt;Inserts the order into the db&amp;lt;/summary&amp;gt;&lt;br&gt;   ///&amp;lt;returns&amp;gt;the id of the new order. (OrderId property is also set.)&amp;lt;/returns&amp;gt;&lt;br&gt;   public int Insert(MyOrder order)&lt;br&gt;   {&lt;br&gt;       //build a dbcommand to insert the order into the database...&lt;br&gt;       //set the OrderId to the new record?&lt;br&gt;       order.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //another impossible call&lt;br&gt;       return order.OrderId;&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&amp;lt;/code&amp;gt;</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229147</link><pubDate>Tue, 14 Sep 2004 01:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229147</guid><dc:creator>Eric Newton</dc:creator><description>ah crap, i screwed up the first set of MyOrders should read Orders... sorry guys! grrr</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229150</link><pubDate>Tue, 14 Sep 2004 01:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229150</guid><dc:creator>Eric Newton</dc:creator><description>Another irritation:&lt;br&gt;&lt;br&gt;internal protected modifiers dont do what you'd expect... the internal keyword takes precedence over the protected modifier, even though you might need for a subclass to be able to call, but you'd like to give the assembly a way to call into it as well...&lt;br&gt;&lt;br&gt;for example:&lt;br&gt;&amp;lt;code&amp;gt;&lt;br&gt;public class Order&lt;br&gt;{&lt;br&gt;   private int _orderId; //orderId should never be settable from outside the assembly&lt;br&gt;   //but what if somebody subclasses the Order?  It would be nice to let the subclass&lt;br&gt;   //be able to set it... AND let the data classes be able to set it when&lt;br&gt;   // Loading an order or Creating a new order [linking the instance to a record in the db&lt;br&gt;   &lt;br&gt;   public int OrderId&lt;br&gt;   { get { return this._orderId; } }&lt;br&gt;   internal protected void Set_OrderId(int value) { this._orderId=value; }&lt;br&gt;&lt;br&gt;}&lt;br&gt;public class Orders  //class handles database interaction&lt;br&gt;{&lt;br&gt;   public Order LoadOrder(int orderId)&lt;br&gt;   {&lt;br&gt;       Order o = new Order();&lt;br&gt;       // build a dbcommand to read a record into a datareader&lt;br&gt;       o.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //can call because in same assembly&lt;br&gt;   }&lt;br&gt;   ///&amp;lt;summary&amp;gt;Inserts the order into the db&amp;lt;/summary&amp;gt;&lt;br&gt;   ///&amp;lt;returns&amp;gt;the id of the new order. (OrderId property is also set.)&amp;lt;/returns&amp;gt;&lt;br&gt;   public int Insert(MyOrder order)&lt;br&gt;   {&lt;br&gt;       //build a dbcommand to insert the order into the database...&lt;br&gt;       //set the OrderId to the new record?&lt;br&gt;       order.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //another impossible call&lt;br&gt;       return order.OrderId;&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&amp;lt;/code&amp;gt;&lt;br&gt;---------------------------&lt;br&gt;make a new project, referencing the above assembly&lt;br&gt;&lt;br&gt;&amp;lt;code&amp;gt;&lt;br&gt;public class MyOrder : Order&lt;br&gt;{&lt;br&gt;    public DateTime MyOrderSpecificProperty { get; set; }&lt;br&gt;    internal new void Set_OrderId(int orderId) //try to use the protected aspect of the member&lt;br&gt;    { base.Set_OrderId(orderId); /* again, impossible */  }&lt;br&gt;    &lt;br&gt;}&lt;br&gt;public class MyOrders  //class handles database interaction&lt;br&gt;{&lt;br&gt;   public MyOrder LoadMyOrder(int orderId)&lt;br&gt;   {&lt;br&gt;       MyOrder o = new MyOrder();&lt;br&gt;       // build a dbcommand to read a record into a datareader&lt;br&gt;       o.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //impossible to do this without making OrderId public somehow&lt;br&gt;   }&lt;br&gt;   ///&amp;lt;summary&amp;gt;Inserts the order into the db&amp;lt;/summary&amp;gt;&lt;br&gt;   ///&amp;lt;returns&amp;gt;the id of the new order. (OrderId property is also set.)&amp;lt;/returns&amp;gt;&lt;br&gt;   public int Insert(MyOrder order)&lt;br&gt;   {&lt;br&gt;       //build a dbcommand to insert the order into the database...&lt;br&gt;       //set the OrderId to the new record?&lt;br&gt;       order.Set_OrderId( (int) dr[&amp;quot;OrderId&amp;quot;] ); //another impossible call&lt;br&gt;       return order.OrderId;&lt;br&gt;   }&lt;br&gt;}&lt;br&gt;&amp;lt;/code&amp;gt;&lt;br&gt;&lt;br&gt;The idea is to force users of Orders to go through a hoop to get a valid Order that represents an Order record in the db, hence no setting OrderId publically... but you run into an inheritance problem...</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229569</link><pubDate>Tue, 14 Sep 2004 19:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229569</guid><dc:creator>Steven Padfield</dc:creator><description>Hey Eric,&lt;br&gt;&lt;br&gt;I would say you should have a protected property so that it can be accessed and mutated by subclasses, but then also have an alternative mutator method marked as internal for other classes within the assembly to set/get the property's underlying data without needing to actually reference the protected property itself.&lt;br&gt;&lt;br&gt;public class Order&lt;br&gt;{&lt;br&gt;   // private field&lt;br&gt;   private int _orderID;&lt;br&gt;&lt;br&gt;   // anyone can read the value&lt;br&gt;   public int OrderID&lt;br&gt;   {&lt;br&gt;      get { return _orderID; }&lt;br&gt;   }&lt;br&gt;&lt;br&gt;   // derived classes from any assembly use this property to set the order id&lt;br&gt;   protected int InternalOrderID&lt;br&gt;   {&lt;br&gt;      get { return _orderID; }&lt;br&gt;      set { _orderID = value; }&lt;br&gt;   }&lt;br&gt;&lt;br&gt;   // non-derived classes within this assembly use this method to set the order id&lt;br&gt;   internal int SetOrderID(int value)&lt;br&gt;   {&lt;br&gt;      _orderID = value;&lt;br&gt;   }&lt;br&gt;}</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#229805</link><pubDate>Wed, 15 Sep 2004 06:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229805</guid><dc:creator>Matthew W. Jackson</dc:creator><description>Yeah, I tend to follow Steven's pattern.  I tend to avoid &amp;quot;protected internal&amp;quot;, since it's really kind of a screwball visibility (there are lots of &amp;quot;exceptions&amp;quot; to the normal rules to accomodate it).  I prefer a protected method and an internal method, usually with the same name appended with &amp;quot;Internal&amp;quot;.&lt;br&gt;&lt;br&gt;I could go for a few more visibilities in the language and runtime, though, since I don't always like exposing internals to everybody else in my library.  I'd like to add the &amp;quot;protected and internal&amp;quot; visibility to C#, but there's not really a good syntax for it (except maybe an awkward &amp;quot;protected &amp;amp; internal&amp;quot;).  I'd also like a visibility for nested classes that was only accessible to an outer class that contains it.  But, what do you call such a thing?&lt;br&gt;&lt;br&gt;I suppose a true &amp;quot;friend&amp;quot; visibility would solve both of these problems.</description></item><item><title>The Loss of Friends</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#230174</link><pubDate>Thu, 16 Sep 2004 00:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:230174</guid><dc:creator>Steven Padfield</dc:creator><description>&lt;a target="_new" href="http://67.174.60.122/blog/archive/2004/09/15/155.aspx"&gt;http://67.174.60.122/blog/archive/2004/09/15/155.aspx&lt;/a&gt;</description></item><item><title>re: New Design Guideline: Avoid Protected Static</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#230539</link><pubDate>Thu, 16 Sep 2004 18:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:230539</guid><dc:creator>Steven Padfield</dc:creator><description>Hey Eric,&lt;br&gt;&lt;br&gt;I did some experimenting and I found that protected internal does indeed do what you want it to do: it only allows a member to be called from the same assembly or from a derived class.  This is consistent with the MSDN documentation.&lt;br&gt;&lt;br&gt;I tried loading your example into the IDE, and after filling in some of the blanks, it compiles fine.  I didn't have to change any of your access modifiers.&lt;br&gt;&lt;br&gt;-Steven</description></item><item><title>protected static &amp;raquo; Blog Archive  &amp;raquo; This just in!</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#607718</link><pubDate>Fri, 26 May 2006 07:18:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:607718</guid><dc:creator>protected static » Blog Archive  » This just in!</dc:creator><description>PingBack from &lt;a rel="nofollow" target="_new" href="http://www.blog.protectedstatic.com/?p=5"&gt;http://www.blog.protectedstatic.com/?p=5&lt;/a&gt;</description></item><item><title> Brad Abrams New Design Guideline Avoid Protected Static | patio umbrella</title><link>http://blogs.msdn.com/brada/archive/2004/09/09/227332.aspx#9772469</link><pubDate>Thu, 18 Jun 2009 06:59:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9772469</guid><dc:creator> Brad Abrams New Design Guideline Avoid Protected Static | patio umbrella</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://patioumbrellasource.info/story.php?id=312"&gt;http://patioumbrellasource.info/story.php?id=312&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>