Thursday, December 10, 2009

using bulit in codes for class properties,methods,comments

here i am going to identify some techniques which are built in visual studio.
you will find that from internet,books but i am discussing it for good programming
practice.


visual studio contains pre written codes for class properties & methods
so you can use for ease of programming.suppose we need to define properties
for the private members of class.we can do it via visual studio refactor
menu and not by hand written codes as follows --

In the class below no properties defined for the private member--
namespace MridulFruitsBusiness
{
    public class Bucket
    {
        private string ownerName;
      
    }
}

now follow-
right click on the ownerName.then click- refactor->Encapsulate Field->ok->apply.
The property code will appear as follows-

namespace MridulFruitsBusiness
{
    public class Bucket
    {
        private string ownerName;
        public string OwnerName
        {
            get { return ownerName; }
            set { ownerName = value; }
        }
     }
}

try to Explore the other pre built items in the refactor menu for methods & others.

when you are developing a enterprise application there may be 100 or more methods
of a class.as a good developer you should let the other coders or users of your
methods about 'what is the task or properties of the methods'.u can use comments
for that.whenever users place the cursor on the method name the respective
comments will be shown so that they know what it does.
these comments are written just before the methods definition by writing '/' three
times as below -

namespace MridulFruitsBusiness
{
public class KeepInBucket
    {
        ///
        /// it keeps the fruits in the bucket by calculation..extra..extra
        ///

        ///
        ///
        ///
        ///
        public string KeepFruits(int value, int keepValue, Bucket bucketObj)
        {
        }
     } 
}
also explore the other type of comments.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger