Design Pattern: Design Patterns are a reusable, high quality solution to a given requirement, task or recurring problem and are commonly defined as time-tested solutions. So basically you have a problem context and the proposed solution for the same. Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.Design patterns have two major benefits.
Factory Pattern in C#
Observer Pattern in C#
It will be something like this (I have not tested the code) public class Filefactory { public File CreateFile(int FileType) { if(FileType == 0) return new Furniture(); else return new Crokery(); } } static void Main() { File file = Filefactory.CreateFile(0); foreach (Items Items in File.Itemss) { Console.WriteLine(" " + Items.GetType().Name); } file = Filefactory.CreateFile(1); foreach (Items Items in File.Itemss) { Console.WriteLine(" " + Items.GetType().Name); } Console.ReadKey(); } when the client(here main method) call the File object, it is not aware about the Concrete object it is working on. and moreover good practice to use Interface when exposing to outer world, not the abstract classes.
"But you used exact class type to create object. example is wrong." If you think its wrong, specify the right one. .
Its just a simple object creation, there is no such thing as factory, you metioned in text "This pattern is used to create concrete class instances without specifying the exact class type" But you used exact class type to create object. Your example is wrong. there is nothing like factory in your example.
Simple and easy and useful article, images will make it more easy to understand
Hi Nipun, Its a very good article..