Search in Help for developer site.

Friday 6 January 2017

The Perfect Real Time Example of Interface in OOPS

 The Perfect Real Time Example of Interface in OOPS

Suppose your parents gives you a list of items to purchase,
that list is an Interface that you will implement at the time of purchasing.....
Means Before implementing any thing , you list out what you have to do that will be an interface......


Now Lets implement it in programming way:-



//Here Parent gives list of Items to purchase.So we listed out the Items
        interface IPurchaseItem
        {
            void PurchaseBook();
        }

        //Implementation while Purchasing.
        class Person1Purchasing:IPurchaseItem
        {
            public void PurchaseBook()
            {
                Console.WriteLine("Hey! I purchased C Sharp Book");
            }
            //other code here
        }
        class Person2Purchasing : IPurchaseItem
        {
            //Different Implementation
            public void PurchaseBook()
            {
                Console.WriteLine("Hey! I purchased Java Programming Book");
            }
            //other code here
        }



Description:-
Here we have one interface having PurchaseBook() method so now it depends on classes how they implement it. So here Person1 purchased C Sharp book and Person2 purchased Java Programming book.



I hope now you have a clear vision about Interface.

Note:-Its my own understanding on Interface.So Please correct me if i am wrong. Write your comments into the Comments section below.


2 comments: