Search This Blog

Saturday, October 13, 2018

Wrapper Class


If we want to hide some set of logic (written in some class) and/or attributes from outside the world then instead of adding access modifier (private specially), we can move all those logic and attributes to some place (class, which encapsulate attributes and actions) and wrap that class within the another class. So by this way we can hide the whole logic from outside the class as by creating the object of the wrapper class we cannot access the method inside the wrapped class.

E.G.

public class WrapperClass
    {
        public int AddNumber(int a, int b)
        {
            return a + b;
        }

        public void AddNumberW(int a, int b)
        {
            WrappedClass wc = new WrappedClass();
           
            Console.WriteLine("Adding specific values using default constrctor= " + wc.AddNumberW(3,5));
        }

        public class WrappedClass
        {
            public int AddNumberW(int a, int b)
            {
                return a + b;
            }
        }
    }

No comments:

Post a Comment


This is a User Friendly Blog.
Simple Interface and Simple Controls are used.
Post your comments so i can modify blog regarding your wish.