Tuesday, 25 February 2020

Abstract factory design Pattern
An interface for creating families of related or dependent objects without specifying their concrete classes.

When we need to create a set of related objects or dependent objects which should be used together as families of objects then we use Abstract factory design pattern.

Lets see the difference between Abstract Factory Design Pattern and Factory Design Pattern in c# with example.

Factory pattern
  • This creates object through inheritance.
  • It produces only one product.
  • This implements code in the abstract creator that makes use of the concrete type that sub class produces.
Abstract factory design pattern
  • Creates object through composition.
  • Produce families of products.
  • Concrete factories implements factory method to create product.

Abstract factory design pattern vs Factory pattern c# with example

Abstract factory design Pattern An interface for creating families of related or dependent objects without specifying their concrete class...

Saturday, 15 February 2020




This video is about Factory Design Pattern in C# with example. Here you will learn what is design pattern, what is factory design pattern - its Creational design Pattern, I will show you simple example without its implementation that means traditional approach and then I will show you implementing the same code using Factory design pattern.

Traditional way Code implementation without Factory Design Pattern:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WithoutFactory
{
    class Program
    {
        static void Main(string[] args)
        {
            Igym obj = null;
            Console.WriteLine("Which Membership you want?");
            string type = Console.ReadLine();
            if (type == "monthly")
            {
                obj = new Monthly();
            }
            else if (type == "yearly")
            {
                obj = new Yearly();
            }
            Console.WriteLine(obj.getcharges());
            Console.ReadLine();
        }
    }
    public interface Igym
    {
        int getcharges();
    }
    public class Monthly : Igym
    {
        public int getcharges()
        {
            return 2000;
        }
    }
    public class Yearly : Igym
    {
        public int getcharges()
        {
            return 8000;
        }
    }  
}


Code implementation with Factory Design Pattern:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WithFactory
{
    class Program
    {
        static void Main(string[] args)
        {
            MembershipFactory obj = new ConcreteMembership();
            Console.WriteLine("which membership charges you want?");
            string type = Console.ReadLine();
            Igym instance = obj.GetGymMembershipType(type);
            Console.WriteLine(instance.getcharges());
            Console.ReadLine();
        }
    }
    public interface Igym
    {
        int getcharges();
    }
    public class Monthly : Igym
    {
        public int getcharges()
        {
            return 2000;
        }
    }
    public class Yearly : Igym
    {
        public int getcharges()
        {
            return 8000;
        }
    }

    public abstract class MembershipFactory //Factory class - Creator
    {
        public abstract Igym GetGymMembershipType(string type);
    }
    public class ConcreteMembership : MembershipFactory //Concrete Creator
    {
        public override Igym GetGymMembershipType(string type)
        {
            switch (type)
            {
                case "monthly":
                    return new Monthly();
                case "yearly":
                    return new Yearly();
                default:
                    throw new ApplicationException(string.Format("membership'{0}' not available", type));
            }
        }
    }
}

Here you saw the difference in traditional way of code implementation and implementing factory design pattern- Factory Design Pattern in C# with example

Factory Design Pattern in C# with example

This video is about Factory Design Pattern in C# with example. Here you will learn what is design pattern, what is factory design pat...

Saturday, 1 February 2020

Welcome to Technical Talks!

Here we are going to see how simply we make an angular app using .Net MVC WebAPI as service and SQL server as a backend.

You will come to know the flow of implementation and live running app.

So in order to get started, lets create a table called 'customers', the script as given below :

Step 1: Create table - customers


CREATE TABLE [customers](
[customer_id] [int] IDENTITY(1,1) NOT NULL,
[first_name] [varchar](255) NOT NULL,
[last_name] [varchar](255) NOT NULL,
[phone] [varchar](25) NULL,
[email] [varchar](255) NOT NULL,
[street] [varchar](255) NULL,
[city] [varchar](50) NULL,
[state] [varchar](25) NULL,
[zip_code] [varchar](5) NULL,
[dob] [date] NULL,
[anniversary] [date] NULL,
PRIMARY KEY CLUSTERED 
(
[customer_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

The table looks as shown below.

Step 2: Create WebAPI Service - ASP.Net MVC WebAPI

In order to build the Restful API and use it in our angular app, here we are going to use ADO.Net Entity Framework.

Let's create the WebAPI project - I name this project as 'API' as shown in below screen. 


Add the ADO.Net Entity Data Model in Models folder of the project and provide the database connection and select the customers table from the list to make use of this table for customer data in API.

Please refer the below screen.


Now lets create a controller called - customers selecting entity framwork type as shown below.
In order to add CORS in our WebAPI, please add the below code in your WebApiConfig.cs file under App_Start folder of the project.

            var corsAttr = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(corsAttr);

so far, we are done with the backend services and now we want to show the data through customers webapi in angular.

Lets move on..

Simple Angular Application - Get started

Welcome to Technical Talks! Here we are going to see how simply we make an angular app using .Net MVC WebAPI as service and SQL server ...

 

Technical Talks © 2015 - Designed by Templateism.com, Distributed By Blogger Templates