Search This Blog

Wednesday, June 9, 2021

Q36-Q40

Q36. What is the difference between the Accept header and the Content-Type header?
Q37. What is Domain Driven Architecture? 
Q38. 
Q39. 
Q40. 

===============================================================================
Q36. What are the differences between accept header and content-type header in sense of content negotiation?

Answer:
In Web APIs, both Accept and Content-Type are HTTP headers, but they serve different purposes:
1. Accept Header
Accept: application/json
means “I want the response in JSON.”

2. Content-Type Header
Describes the format of the actual body being sent.
Content-Type: application/json
means “The body I’m sending you is JSON.”
 
===============================================================================
Q37. What is Domain Driven Architecture? 

Answer:
  • Most moderns ORM follow domain driven architecture like entity framework. 
  • They have domain classes which are actually POCO (plain old C# object) classes which are entity classes 
  • We usually use Repository pattern with Domain Driven architecture. 


===============================================================================
Q38. 

===============================================================================
Q39. 


===============================================================================

===============================================================================

Sunday, June 6, 2021

Q31-Q35

Q31. Give real life example of abstract class usage in your project?
Q32. What is dictionary?
Q33. How to sort elements in dictionary by value? 
Q34. What are delegates? How it is related to lambda expression. 
Q35. What is event driven programming?

===================================================================================
Q31. Give real life example of abstract class usage in your project?

Answer:
In my project we have a abstract repository Generic class so that all the repositories will have basic functionality of repository and they need not to implement again and again unless required.

public abstract class Repository<T> 
{
    //some simple methods, which will be called from all repository

public void InsertonSubmit(T entity)
{
//
}

//some virtual methods, which can be changed if required
public virtual void UpdateonSubmit(T entity)
{
//
}

//Some abstract method, which always depend on derived class but we want to enforce the //remembrance of writing logic

public abstract void ChangeSessionValues(T entity)

// child class will give definition.
}


===================================================================================
Q32. What is dictionary?

Answer:
public class Dictionary<TKey,TValue> 

Dictionary<string, string> openWith =     new Dictionary<string, string>();
openWith.Add("txt", "notepad.exe");
openWith.Add("bmp", "paint.exe");

Console.WriteLine(openWith["bmp"]);

===================================================================================
Q33. How to sort elements in dictionary by value? 

Answer:
Dictionary is a collection thus linq and lambda can be applied on it. 

var ans = openWith.orderby(key=>key.value

===================================================================================
Q34. What are delegates? how it is related to lambda expression

Answer:
Delegates are pointer to the function. Delegates are of two types 1. Singlecast and 2. Multicast. 

Lambda expression - is an anonymous method that can be used to create delegates. 
When you create delegates you can pass method name as a parameter to delegate object. 

  1. using System;  
  2. namespace DAL {  
  3.     public delegate void MyDelegate();  
  4.     class Program {  
  5.         public void CallerOne() {  
  6.             Console.WriteLine("This is Caller One function...");  
  7.         }  
  8.         static void Main() {  
  9.             //Create object of the class and give it an instance  
  10.             Program p = new Program();  
  11.             //Crete the object of delegate and note that you have to pass the method as parameter  
  12.             MyDelegate myDelegate = new MyDelegate(p.CallerOne);  
  13.             myDelegate();  
  14.         }  
  15.     }  
  16. }   

Multicast Delegate
  1. using System;  
  2. namespace DAL {  
  3.     public delegate void MyDelegate();  
  4.     class Program {  
  5.         public void CallerOne() {  
  6.             Console.WriteLine("This is Caller One function...");  
  7.         }  
  8.         public void CallerTwo() {  
  9.             Console.WriteLine("This is Caller Two function...");  
  10.         }  
  11.         public static void CallerThree() {  
  12.             Console.WriteLine("This is Caller Three function...");  
  13.         }  
  14.         static void Main() {  
  15.             //Create object of the class and give it an instance  
  16.             Program p = new Program();  
  17.             //Crete the object of delegate and note that you have to pass the method as parameter. This is Single Cast  
  18.             MyDelegate myDelegate = new MyDelegate(p.CallerOne);  
  19.             //Crete the object of delegate and note that you have to pass the method as parameter. This is Single Cast  
  20.             MyDelegate myDelegate1 = new MyDelegate(p.CallerTwo);  
  21.             //Crete the object of delegate and note that you have to pass the method as parameter. This is Single Cast  
  22.             MyDelegate myDelegate2 = new MyDelegate(CallerThree);  
  23.             myDelegate();  
  24.             myDelegate1();  
  25.             myDelegate2();  
  26.             //This Idea is Called Multi Cast  
  27.             MyDelegate MyDelegate_MultiCast_Idea = myDelegate + myDelegate1 + myDelegate2;  
  28.             MyDelegate_MultiCast_Idea();  
  29.         }  
  30.     }  

Lambda Expression -- It reduces the reference to the method name part. as it become the part of delegate itself as an anonymous method. 

  1. using System;  
  2. namespace DAL {  
  3.     public delegate void MyDelegate();  
  4.     class Program {  
  5.         static void Main() {  
  6.             //Here '=>' thing work to implement Labda Expression. It can be further dicsussed but I will discuss this in future article.  
  7.             MyDelegate myDelegate = new MyDelegate(() => {  
  8.                 Console.WriteLine("This is Caller One function...");  
  9.             });  
  10.             myDelegate();  
  11.         }  
  12.     }  
  13. }   

===================================================================================
Q35. What is event driven programming?

Answer:
As the name suggest this technique uses events as base for developing the software. We can have a software which is running without any interaction with events but usually these days software are developed with event interaction. events could be mouse click, uploading a video, visiting a new page etc. 

===================================================================================