Tuesday, April 12, 2016

Extension Methods

Extension method is a new feature introduced by C# 3.0. Extension method enables to add new methods in existing class without making any change in source of main class. Even there is no need to re-compile that class for which you have added extension method. Also without using inheritance. Although if have not the source code of class only dll is there than too you can add extension method.

Features

1. Extension method should be static
2. The class where it is defined it also should be static.
3. You cannot override the existing method using extension method.
4. If there is a method already in the class with same signature and name than extension method will not be called.
5. To define the parameter list of extension method this keyword used as first parameter than class name after then a variable name( any valid variable name).
6. If you will press the dot after the object the extension method will appear by VS intellisense.
7. It is application only for methods. Same concept cannot be applied for fields, properties and events.
8. It is different from only static method they can be called by object.
9. It can be in same namespace where it is using or in different one.
10. The object which is calling extension method it is passed automatically to extension method as parameter.
11. Extension method with parameter: Parameter also can be passed in extension method.

Using Code

Suppose you want to add some extension method in a system defined class. Take String for an example.

using System;

namespace UserDefined
{

public static class UserClass


{


public static String ConvertToTitleCase(this string strInstance)
{

Char[] charArray = new char[] { ' ', '.', '?' };

string[] strNew= strInstance.Split(charArray, StringSplitOptions.RemoveEmptyEntries);

for(int i=0;i
{
strNew[i][0] = strNew[i][0].ToUpper();
}
return strNew;
}
}
}

Here ConverToTitleCase is an extension method that can be used anywhere if this name space is included in your class. Here we have taken the example of string class but it can be with any user defined class.

Now we can use this method as shown below.

using System;

namespace Sample
{

class Program
{

static void Main(string[] args)
{

string userInput = string.Empty;
Console.WriteLine("Please Enter your String");

userInput = Console.ReadLine();
//calling Extension Method ConverToTitleCase()

String Output= userInput. ConverToTitleCase();

Console.WriteLine("Output title case string is :"+Output);

Console.ReadKey();

}
}


}


Drawback:


This is not a good practice to use extension method because of static keyword and static keywords take memory for entire program life.

Dependency Injection Container

Friday, April 8, 2016

Web Stack

Web stack – The web stack is a collection of utilities (software) required for web development. It contains at least an Operating System, a Programming Language, database and web server.
One Example of Web Stack is LAMP. It uses Linux as an O.S, Apache as a Web Server, MYSQL as a database, and PHP as an object oriented scripting language
A web stack is a type of solution stack--- An ordered collection of software that performs a particular task.
Solution stack is a complete set of software required to develop and run the application such that no additional software required from outside other than stack.


Server Stack – Server Stack is a collection of software that forms the operational infrastructure on a given machine, in a computing context, a stack is an ordered pile. A server stack is a type of solution stack. As name indicate server stack means it contains all software to make a machine as a server.


Client Stack – Client stack includes OS and its supporting software as well as runtime environments like JRE. It includes all the software that is required run an application on a client machine.


Persistence (Database) Layer – Persistence layer responsible for CRUD (Create, Read, Update and Delete) operation, Enforce data integrity constraint, validation, transaction, connection pooling and security.


Application Services Layer (ASL) – Orchestrates lower level, chattier methods to solve higher level domain specific problems. ASL has methods that serve the Presentation Layer


Web Service Layer:
1.      The webservice layer serialize the request from Presentation Layer and application layer same way it also de-serialize the response to Presentation layer and application service layer.
2.      Web services depends on standards.
3.      And expose the web method to client application
4.      Webservices methods expose the functionality of Domain Layer of Application Session Layer.

5.      Webservices has well defined end points.

Architecture fundamentals


· BDUF: Big Design, Up Front

Big Design Up Front is an approach in software development that software design should be perfect and completed before implementation started.

· Separation of Concerns: Defined as logical grouping of responsibilities.

It is one of the design principle. Divide the application into different section. Every section should refer to different concern. 

· SRP: Single Responsibility Principle, to reduce coupling

Single Responsibility principle states that every class should have only one reason to change. It means every class should have single responsibility.

· DRYP: Don’t repeat yourself principle.

DRDYP states that “every piece of information should be unique and unambiguous. You can implement the DRYP by breaking the code into functions and call them instead of copy paste the code more than one place.

· Open Closed principle.

A class should be open for extension but closed for modification.

· Liskov Substitution principle.

A parent should be able to replace its child. Means if a class A inherited an interface which contains 3 method but one method no use for class A than better is break this interface into two interfaces.



· Interface Segregation

A client should not be force to use an interface if it does not need it.



· Dependency Inversion Principle.

High Level Module should not depend on Low level module. Both should depend on abstraction.

Dependency Injection

Dependency Injection (DI):- Dependency Injection is a Software design pattern. Before dipping into Dependency Injection we need to understand about Dependency Inversion Principle and Inversion of Control. After than we will be at better place to understand Dependency Injection.

Dependency Inversion Principle: Dependency Inversion Principle is a design pattern. It states that
1.         High Level Module should not depend on low level modules, both should depend on Abstractions.
2.         Abstractions should not depend on detail. Detail should depend on Abstraction.

Let’s understand what the problem was before Dependency Injection Principle introduced.

Class WriteLog
{    
      Public void WriteError ()
      {
                  //Write Log here
}
}

Class Employee
{
     // Handle to EventLog writer to write to the logs
     WriteLog objCWriteLog =null;        

    // This function will be called when any error ocuuerred
    public void WriteError(string message)
    {
        if (objCWriteLog == null)
        {
            objCWriteLog = new CWriteLog ();
        }
        objCWriteLog.Write(message);
    }
}

In above example code looks fine but there is a problem. Here High level module( Employee class) is depend of low level module, Suppose you need to send a mail to developer id in case of error instead of writing into error file. In that case you create a class MailSender and again put that class object in Employee class. So you have to modify the code of Employee. And in case if there is need to use only one object than it will have another problem. 
  
Inversion of Control

So problem was solved by Dependency Inversion Principle. Dependency Inversion Principe states that every module should be decouple instead of tight couple, such a way that higher level module should depend on simple Abstraction rather than concrete implementation.

            Let’s understand with an example

            First create an Interface

            public interface ILog
{
void WriteError (string text);
}

Than modify the Employee class as

      Class Employee
{
       ILog writer =null;    

       // This function will be called when there is an error
       public void WriteError(string message)
       {
               writer.Write(message);
      }
}

And WriteLog class will be change like that
class WriteLog: ILog
{  
    public void WriteError (string message)
    {
        // Write to event log here
    }
}

Now it will be easy to add one class for sending eMail
class EmailSender : ILog
{
    public void WriteError (string message)
    {
        // Send email from here
    }
}

So here we have inverted the control similar to dependency inversion principle. Now higher level control are dependent on Abstraction rather than lower level control. You can say this model follow Dependency Inversion Principle now. And Employer class can be created like that

Class Employee
{
     // Handle to EventLog writer to write to the logs
     ILog logger =null;     

    // This function will be called when there is an error
    public void WriteError(string message)
    {
        if (objCWriteLog == null)
        {
            logger = new CWriteLog ();
        }
        objCWriteLog.Write(message);
    }
}

If you will see the above class you will notice that we are back to where we have started. The concrete class creation inside higher level class. Can we not create Employee class completely decouple? Here is the situation where Dependency comes in picture.

Dependency Injection

Dependency Injection means injecting the concrete implementation into a class which is using Abstraction i.e. interface. Main purpose of Dependency Injection is remove the coupling between classes and put the concrete implementation out of class.
There are three ways to do Dependency Injection.
1.    Constructor Injection
2.    Method Injection
3.    Property Injection

Constructor Injection: Constructor Injection means inject the concrete class object through constructor rather than creating inside High Level module.

class Employee
{ 
    ILog action = null;

    public Employee (ILog concreteImplementation)
    {
        this.action = concreteImplementation;
    }

    // This function will be called when the app pool has problem
    public void WriteError(string message)
    {  
        action. WriteError (message);
    }
}

Now Employee object will be create like that
WriteLog objWrtieError = new WriteLog();
Employee objEmp = new Employee(objWrtieError);

EmailSender objMailSender = new EmailSender();
Employee objEmp = new Employee(objMailSender);

Method Injection: Method Injection means is passing the concrete class object through method.
In precious approach there was a drawback same object will use in entire class if you need different object for different method than we use method injection.


class Employee
{
    ILog action = null;

    public Employee ()
    {
    }

    // This function will be called when the app pool has problem
    public void WriteError(ILog concreteImplementation  string message)
    {  
        this.action = concreteImplementation;
        action. WriteError (message);
    }
}

Now class Employee object will be modifiedlike that
WriteLog objWrtieError = new WriteLog();
Employee objEmp = new Employee();
objEmp. WriteError(objWrtieError ,message);


EmailSender objMailSender = new EmailSender();
Employee objEmp = new Employee();
objEmp. WriteError(objMailSender,message);

Property Injection: If we need to use concrete object in different class than we use property injection.

class Employee
{
    // Handle to ErrrorLog writer to write to the logs
ILog action = null;  
 public ILog Action
 {
        get
        {
            return action;
        }
        set
        {
            action = value;
        }
    }

    // This function will be called when the app pool has problem
    public void Notify(string message)
    {  
        action.WriteError(message);
    }
}

Thursday, April 7, 2016

Interview Questions 13

There are TWO PARTS in this paper. PART ONE contains THREE questions and PART TWO contains SIX questions. PART ONE is to be answered in the SPECIAL ANSWER SHEET only, attached to the ANSWER BOOK, as per the instructions contained therein.

TOTAL MARKS: 100 (PART ONE - 30, PART TWO - 70) PART 1 (Answer all the questions) 1 Each question below gives multiple choices of answers. Choose the most appropriate one and enter in the "SPECIAL ANSWER SHEET" attached to the ANSWER BOOK, following instructions therein. (1 X 10) 1.1 A list of items, in which additions and deletions may be made at either end is known as a jy Queue. B. Push-down stack C. Deque D. None of the above 1.2 Reentrant code provides for A. Execution of object program instruction segments by more than one process at the same time. J1. Improved console operations. C. Multiprocessing D. Contiguous areas of memory for storage of program, variables, data, reference, and dynamic process history. Which is not a debugging technique A. Core dumps Traces B. Print Statements D. Regression Testing

1.3

-e:

1.4

The A. B. C.

.p.

process of transforming a model into source code is Reverse Engineering Forward Engineering Re-engineering Re-structuring

1.5 The process by which existing processes and methods are replaced by new processes and techniques is A. Reverse Engineering B. Business Process Re-engineering C. Software Process Management Forward Engineering

».

1.6

init and cron are: ft.. linux processes B. DOS processes C. Windows processes D. None of the above. The differences between constructors and destructor in C++ are A. constructors can take arguments but destructor can't B. constructors can be overloaded but destructor can't be overloaded .AJ. both A & B D. none of these Use A. ..E. C. D. Case is a: case in case/switch statement in a programming language . a part of use case diagram, a modeling element. special case in legal cases in computer industry. None of the above.

1.7

1.8

1.9

PATH A. is a system variable naming the list of directories required to be searched for finding the commands to be executed. vi3. is a path to be followed in finding Critical Path Method in Pert/CPM techniques C. is a system variable naming the list of directories required to be searched for finding a class. D. None of the above.

1.10 When a language has the capability to prod\lce new datatype, it is called ~ Extensible B. Overloaded C. Encapsulated D. Reprehensible

2

Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the "SPECIAL ANSWER SHEET" attached to the ANSWER BOOK, following instructions therein. JavaScript is an old version of Java Language.

2.1 2.2 2.3 2.4

'I (j)

Maintenance stage in SDLS precedes Implementation . ../' Symbian is an operating system. X-

(j)

Hotswappable hard disks requires systems to be closed and cooled before they can be removed. ~ PHP and Perl are examples of spreadsheet packages .

2.5

.:x! (!)

2.7

The fields in a C++ program are by default private.

vi'

(j)

2.9

A return code of 0 from a function is interpreted that there are errors during its execution. 'I When a variable is passed by reference to a procedure, the changes made to the variable are passed back to the calling procedure. ;/'

2.10

3

Each statement below has a blank space to be filled. Enter your choice in the "SPECIAL ANSWER SHEET" attached to the ANSWER BOOK, following instructions therein. (1 X 10) interface.

3.2 3.3

The time required by a sector to reach below the read/write head What will be the output of the following code snippet
c

I~

7'
I"

r /. Ie ~ J)v

try { int x = 0; int y = SO/x; System.out.println("Division by Zero is an error"); } catch(ArithmeticException e) { System.out.print1n("catch block"); } In a select statement clause restricts the grouped rows that appear in 1f\1' the result.

/ul

11;

3.5 3.6 3.7

The process of mapping/initialising a disk is called A popular open source DBMS

/,"zl,£

'1

J'&l

J2 2=)!~;4""

An image scanner with tit YCbtvf software can translate a scanned text into text that can be edited.

3.8

A BIOS routine called , that run~ whenever the system determine the functioning of various parts of the computer system.

l~

started to

PART 2 (Answer any five questions) 4 Write short note on 4. De-fragmentation, compression and encryption .-b. Open Source, Commercial Software and Freeware c. Paging and Segmentation d. SDLC and its stages

fl

What do you understand by Complexity of Sorting Algorithms? Explain in the context of various sorting techniques. b. Write Quick Sort Algorithm using pseudocode and verify your code by tracing an example.

~. Explain final, finally, finalise, this and super in Java Context b. Consider the following stack, where stack is allocated N = 6 memory cells STACK: AAA, DDD, EEE, FFF, GGG, _ Describe the stack as the following operations take place: (i) PUSH(ST ACK,KKK), (ii) POP(ST ACK,ITEM), (iii) PUSH(STACK,LLL), (iv) PUSH(STACK,SSS), (v) POP(ST ACK,ITEM), (vi) PUSH(STACK,TTT) c. What does chmod, vi and grep do in linux system?

a. What is Object Oriented Programming? Why is Java called portable or platform independent language b.Write a program(in Java or C++) to produce fibonacci numbers FO, Fl given below. Should one use recursion or iteration for the above program and why? n=O, n=l, n>=2

Fn = {~ Fn-l + Fn-2

a. Let a and b denote positive integers. Suppose a function Q is defined recursively as follows Q(a,b) = { 0 Q(a-b,b) + I ifa
(i) Find the value ofQ(2,3) and Q(l4,3) (ii) What does this function do? Find Q(5861,7). c-b. Describe Method Overloading and Method Overriding. c. Let LIST be a linked list in memory. v\7ritea procedure which finds the number NUM of times a given ITEM occurs in LIST

,<

a. Based on type of organization of data what are different types of DBMS? Oive examples of commercially available DBMS's today. b. An organization conducts training programmes (courses) for its own employees. '" These employees are recognized in the organization by an ~mployee code and are placed in different specialized groups called Divisions headed by HODs (who are also employees). Design a fully normalized database, clearly indicating primary key and foreign key constraints, to store following information: Employee Name, Employee Code, Designation, Division Name, HOD Name, Course Title (Training Programme Title), Course Start Date, Course Duration etc Write SQL statementto generate (i)Division wise (List of all employees in a division) with the HOD Name (ii)List of courses attended by a particular employee (iii)List of employees who have attended a particular training programme c. Describe ACID in the context of DBMS.

Difference Between Globalization and Localization


Globalization is the process of designing and developing applications that function for multiple cultures. Localization is the process of customizing your application for a given culture and locale.

Friday, April 1, 2016

Interview


1. Difference between Specialization and Generalization
2. Diff between between Agregation and Composition
3. Difference between Truncate and Delete. Click Here
4. What is Modal Vendor?
5. What is Transaction in WCF?
6. Difference Between Interface and Abstract class? Click Here
7. If you have User control with a submit button on it and you want to fired click event of submit button on page load? What is the way?
8. What is thread Affinity? Click Here
9. What is Dispatcher? Click Here
10. What is Web API?
11. What is REST?


Windows Presentation Framework

Window Presentation Framework is Microsoft tools for website development and rich client applications. It is previously known as Avalon. WPF is an approach of Microsoft to a GUI framework.
If you have to use Forms and Controls, Windows form is best for that, for fixed format document pdf is good, for Image GDI_ is better, For Audio and Video Windows Media Player is nice, for two dimensional graphics GID+ is right, for three dimensional graphics Direct3D is wonderful but what if you have use all the feature in single platform, WPF is comes in scene for that.

Difference between WPF, GDI, GDI+, and DirectX?


GDI application use Operating System Controls to build its application, which are very hard to customize.  WPF controls are drawn on screen, which are easy to customize.
WPF is not a replacement for DirectX but for Windows Forms.

Features

1.       Fixed and Flow format documentation.
2.       Device Independent Pixel Format.
3.       Window Form use Pixel based approach , when DPI change than controls also change their size and look while WPF control are DPI independent
Suppose you have drawn a 2 inch box and you were working with 96 DPI screen if you see the same application in 120 DPI screen the will appear relatively small. Because screen are dependent on DPI setting

While WPF uses density based approach, So when the density of pixel has been changed the element will adjust them accordingly, if you will repeat the above scenario with WPF application than box size will not change, hence it takes more pixel in case of 120 DPI application to adjust the size properly.

4.       All the capabilities of HTML and Flash.
5.       2D and 3D vector graphics.
6.       Animation
7.       Multimedia
8.       Data Binding
WPF use XAML (Extensible Application Markup Language);
XAML is compiled into IL (just like C# or VB)

Advantage of WPF over Window Form

1.       Common Look and Feel
2.       Anywhere Execution
3.       Binding
4.       Directive Programming (i.e. Less Code)
5.       Graphic Independency
6.       Faster execution (Hardware Rendering)
7.       Expression Blend and Animation
8.       Built in Support for Graphics and Animation: - WPF application are rendered within DirectX environment. There graphics here are vector based, figure drawn here act as an object you can select the rectangle drawn in WPF and delete also unlike traditional rectangle in drawn in Windows form using GDI.

XAML can be used in WPF, WWF and in Silverlight.

Architecture of WPF

Above figure shows the architecture of WPF. There are three main component of WPF shown with gray color
1.       Presentation Framework   2. Presentation Core 3. MilCore.
The figure shows how direct x and operating system contact with other components.
Let’s see what the different components do.
User32: User32 determine what goes where on the screen.
Direct X:  WPF internally uses direct X. On the other side DirectX talks with drivers and renders the content.
Milcore: Media Integration Library, It is a manage code that works like a bridge between WPF managed code and User32.
Presentation Core: This is a low level API exposed by WPF that provide features like 2D, 3D and geometry.

Presentation Framework: User directly contact with Presentation Framework. It contains Layout, Controls, and Contents etc.

System.Threading.DispatcherObject

The base class of all WPF object is DispatcherObject. WPF support SingleThreadedApartment model. DispatcherObject mainly handles concurrency and threading. Messages like button clicks, mouse clicks are first send to DispatcherObject, It verifies whether code is running on same thread.

Are XAML Files complied or built at runtime?


XAML files are not generally parsed at runtime, they are complied. But they can parsed also. A Xaml based project creates .g.cs file for every .xaml file after building inside obj\Debug folder. 

Followers

Link