c# - When to call base.method() and what code should go in a base.method()? -


In the following sample, the authors of the derived class will be expected to call the base. If this happens 1, the base can make a type of code if it is final, the base can make the second type of logic (see sample). I do not think this is possible in both ways and it will be easy to call the base method, because the foundation will never know that it is called first, last or middle or twice!

What is the object oriented approach to dealing with this? Should I stop putting code only in basic methods because I will never know the situation before and after?

Edit: The target is to classify a business object that runs the CRUD, the repeated code will be transferred to the base class. For example, to see that before adding a record, the business object's ID is 0 and after saving it is checking that the Business Object ID is> 0.

  Nameshon Stack OverflowCommunications {class BusinessObjectBase {Private bool _New; Private INID; Add public virtual zeros (string newaccount) {// code when subclasses run this pattern with the same equality // It is understood that if the base is given 1 name then (_isNew & amp; _id & Gt; 0) New Invalid Operation Expansion ("Invalid pre-condition state"); // It is understood that if BAE is called 2 then (! _isNew & ADID == 0) throw a new invalid operation exception ("invalid post status status"); }} Class BusinessObject: BusinessObjectBase {Public Override Add Zero (String NewEquint) does not mean, Base has to be called again; Base.Add (newAccount); // Pre-verification, logging // Save the new database // does not make sense, because the base is already called the base.Ad (newAccount); // post verification, logging}}}  

If you start to get a safe Want to pre-post and post status check, you can add non-virtual, and instead of another method (AddInternal or something) that can override derived classes (or should?):

  Namespace Stack Overflow {Sarvar Business} {Private Bull _isNew; Private INID; Protected abstract Zero AddInternal (string newAccount); Add Public Zero (String Newaccount) (If (_isNew & amp; _id & gt; 0) throw a new invalid operation exception ("Arun pre-condition state"); AddInternal (newAccount); If (! _isNew & amp; _id == 0) New Invalid Operation Exception ("Invalid Post Status Status");}} Category BusinessObject: BusinessObjectBase {Protected Override Zero AddInternal (String NewEquint) {// Save new account for data}}}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -