Archives

All posts by Pavlović Branislav

A widget for Microsoft Power BI, using NodeJS packages and TypeScript


The Journal is into the articles from the sphere of general medicine and other medical disciplines which might be of interest to General/Family medicine. 

The Section of General Medicine of the Serbian Medical Society is the founder, owner, and publisher of the Journal Opsta medicina.

http://www.generalpracticejournal.org

http://www.casopisopstamedicina.org

Abstract Factory provide common interface for a group of similar classes, without creating concrete class.

public interface IClass{
          public string GetMethodResult();
} 
public class ClassA : IClass{
         public string GetMethodResult(){
                return "Result from Class A";
         }
}

public class ClassB : IClass {
        public string GetMethodResult(){
               return "Result from Class B";
        }
}

public interface IFactory{
          public IClass CreateClass();
}

public class ClassFactoryA : IFactory{
         public IClass CreateClass(){
                return new ClassA();
         }
}


public class ClassFactoryB : IFactory {
        public IClass CreateClass(){
               return new ClassB();
        }
}

public enum ClassType {
       Class_A, Class_B
} 

void Main{
       IFactory factory;
       switch(type){
           case type.Class_A:
                factory = new ClassFactoryA();
           case type.Class_B:
                factory = new ClassFactoryB();
        }
       var aClass = factory.CreateClass();
       var result = aClass.GetMethodResult();
        
} 

Define an interface for creating an object, but let sub-classes decide which class to instantiate. Factory Method lets a class defer instantiation to sub-classes.

That means, You can create a object without specifying exact class, by using /calling factory method.

public interface ISubClass{
          public string GetMethodResult();
} 


public class ClassA : ISubClass {
         public string GetMethodResult(){
                return "Result from Class A";
         }
}


public class ClassB : ISubClass {
        public string GetMethodResult(){
               return "Result from Class B";
        }
}

public enum ClassType {
       Class_A, Class_B
} 

public class ClassFactory{
       public ISubClass GetClass(ClassType type){
               switch(type){
                    case type.Class_A:
                             return new ClassA();
                    case type.Class_B:
                             return new ClassB();
                }
        }
} 

New interesting blog with stunning stories.

http://www.tijanapavlovic.com