The Tenets of MVC


Following are the tenets of MVC:


  • Separation of concerns
                      Foundation concept of a good application is that it should be modularized. So that each module focuses on its own module. In MVC, Model knows nothing about the View and the Controller. The View knows nothing about the Controller and so on. The more you keep the application separate the more it will perform better and it will be more maintainable. That's separation of concerns.
  • Convention over configuration
                    The ASP.NET MVC eliminates the need for extensive configuration settings by following various conventions. Example would be in MVC project has separate folders for Module, Views and Controller. Convention locations to locate code files that implement those different components. By keeping those component in convention folders you don't have to make extensive configuration changes.
  • Keep it DRY: Don't Repeat Yourself
                   DRY is one of the design principle that MVC embraces. The point here is you should reduce the duplication of code and logic which help in making the application faster as well as easier to maintaining. For example you can encapsulate chunk of reusable user interface code in partial view temples which are similar to asp.net user controls. 
  • Be helpful, but get out of the way
                 MVC allows you to have more control over HTML then ASP.NET web pages. It help you to fully customize the HTML view as per your need.

  

Angularjs - Hello World!


What is Angularjs?

AngularJS is a javascript framework which helps build web and mobile application. It is one of the projects developed by Google Inc. It is the widely used client side scripting language.

Google has made this project opensource which mean the source code is available for all. It can be re-modified and used for other projects. It is best fit for SPA (Single Page Application), MVC framework web application etc..,

Visit website Made With Angular (Click Here) to know the top websites which uses Angular JS.

Talking about benefits of Angular JS:
  1. Dependency Injection
  2. Two Way Data-Binding
  3. Testing
  4. ModelViewControler
  5. Directives, Filters etc.,
To get started you need to have angular.js file added to your project. You can download the file or use the CDN link.

Download AngularJS version 1.5.5 file from here

Google CDN Minified : https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js
Google Uncompressed : https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js

Why Google CDN?

While downloading and using the AngularJS source code is great for development, we recommend that you source the script from Google's CDN (Content Delivery Network) in your deployed, customer facing app whenever possible. You get the following advantages for doing so:

Better Caching : If you host AngularJS yourself, your users will have to download the source code atleast once. But if the browser sees that you are referring to Google CDN's version of AngularJS, and your user has visited another app which uses AngularJS, then he can avail the benefits of caching, and thus reduce one download, speeding up his overall experience!

Decreased Latency : Google's CDN distributes your static content across the globe, in various diverse, physical locations. It increases the odds that the user gets a version of AngularJS served from a location near him, thus reducing overall latency.

Increased Parallelism : Using Google's CDN reduces one request to your domain. Depending on the browser, the number of parallel requests it can make to a domain is restricted (as low as 2 in IE 7). So it can make a gigantic difference in loading times for users of those browsers.


Angular example:











AngularJS starts automatically when the web page has loaded.

The ng-app directive tells AngularJS that the <div> element is the "owner" of an AngularJS application.

The ng-model directive binds the value of the input field to the application variable name.

    The ng-bind directive binds the innerHTML of the <p> element to the application variable name.

Normalizing and Denormalizing Data


After designing a database, it is important to ensure that the data in the table is consistent and relevant. Normalization is a process of reducing the redundancy of data in a relational database. The reversal of normalization to improve performance due to some factors is called Denormalization.



Redundancy means repetition of data. Redundancy increases the time involved in adding, updating, and deleting data. It also increases the utilization of disk space and hence, disk I/O increases.


HTML 5.0 - The most powerful yet!


HMTL 5 is the latest version. HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create static web pages. It is written in the form of HTML elements consisting of tags enclosed in angle brackets (like ).








Below is the syntax for HTML 5.0:

<!DOCTYPE html>
<html> 
   <head>
      <title>Page Title</title> 
      <meta charset="UTF-8">
   </head> 
   <body> 
      <h1>This is a Heading</h1> 
      <p>This is a paragraph.</p>
   </body>
</html>


The first "working draft" of HTML5 came out in January of 2008 and it already has surprisingly broad browser support. However HTML5 is not yet fully implemented and won't be for some years yet. There are any number of planning committees that have plans to make it a "Recommendation", but such plans are still in the planning phase.

Two groups, the W3C and the WHATWG, are in charge of developing HTML5. Why two groups? "The WHATWG was formed in response to the slow development of web standards monitored by the W3C." wikipedia – In other words they got in a fight and parted ways.

Fundamental changes are coming with the development of APIs that will run in HTML5 – exciting and powerful new tools that will take the internet places we can't begin to imagine. Also new elements such as the <header>, <nav> and <article> have been introduced which will help search engines analyze web pages better.

HTML5 is not just the future of web design, it's the present.

Quick look at "New Features of ASP.NET MVC 4.0 Framework"



The ASP.NET MVC framework provides the following features:

  • Separation of application tasks (input logic, business logic, and UI logic), testability, and test-driven development (TDD). All core contracts in the MVC framework are interface-based and can be tested by using mock objects, which are simulated objects that imitate the behavior of actual objects in the application. You can unit-test the application without having to run the controllers in an ASP.NET process, which makes unit testing fast and flexible. You can use any unit-testing framework that is compatible with the .NET Framework.

  • An extensible and pluggable framework. The components of the ASP.NET MVC framework are designed so that they can be easily replaced or customized. You can plug in your own view engine, URL routing policy, action-method parameter serialization, and other components. The ASP.NET MVC framework also supports the use of Dependency Injection (DI) and Inversion of Control (IOC) container models. DI enables you to inject objects into a class, instead of relying on the class to create the object itself. IOC specifies that if an object requires another object, the first objects should get the second object from an outside source such as a configuration file. This makes testing easier.

  • Extensive support for ASP.NET routing, which is a powerful URL-mapping component that lets you build applications that have comprehensible and searchable URLs. URLs do not have to include file-name extensions, and are designed to support URL naming patterns that work well for search engine optimization (SEO) and representational state transfer (REST) addressing.

  • Support for using the markup in existing ASP.NET page (.aspx files), user control (.ascx files), and master page (.master files) markup files as view templates. You can use existing ASP.NET features with the ASP.NET MVC framework, such as nested master pages, in-line expressions (<%= %>), declarative server controls, templates, data-binding, localization, and so on.

  • Support for existing ASP.NET features. ASP.NET MVC lets you use features such as forms authentication and Windows authentication, URL authorization, membership and roles, output and data caching, session and profile state management, health monitoring, the configuration system, and the provider architecture.
Source: MSDN

In simple words "Introduction to ASP.NET MVC"


The Model View Controller (MVC) architectural pattern separates an application into three main components: Model, View, and Controller.

ASP.NET MVC Pattern

The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating Web applications. The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly.

MVC is a standard design pattern that many developers are familiar with. Some types of Web applications will benefit from the MVC framework. Others will continue to use the traditional ASP.NET application pattern that is based on Web Forms and postbacks. Other types of Web applications will combine the two approaches; neither approach excludes the other.

The MVC framework includes the following components:

·    Models: Model objects are the parts of the application that implement the logic for the application's data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in a SQL Server database.

In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a dataset and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the dataset takes on the role of a model object.

·     Views: Views are the components that display the application's user interface (UI). Typically, this UI is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Product object.

·    Controllers: Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database.

The MVC pattern helps you create applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The pattern specifies where each kind of logic should be located in the application. The UI logic belongs in the view. Input logic belongs in the controller. Business logic belongs in the model. This separation helps you manage complexity when you build an application, because it enables you to focus on one aspect of the implementation at a time. For example, you can focus on the view without depending on the business logic.

The loose coupling between the three main components of an MVC application also promotes parallel development. For example, one developer can work on the view, a second developer can work on the controller logic, and a third developer can focus on the business logic in the model.

What are the Characteristics of the Object-Oriented Approach?


Following are the characteristics of the Object-Oriented Approach:

  • Realistic Modeling
       


The Object-Oriented approach allows you to identify entities as objects having attributes and behavior. Attributes and behavior typically dipct how the object acts and reacts. For example, the car is an object belonging to the class Vehicle. The car has attributes such as speed, color, and power. It displays behavior such as being stationary, moving slowly, or accelerating.

  • Reusability


          In programming word, using existing classes or objects form other application saves resources spent in recreating the classes from scratch. The process of creating a new class by adding some features to an existing class is known as inheritance. The benefit of reputability translates to savings in time and effort, which in turn results in cost benefits.

  • Resilience to Change
          In the object-oriented system, this requirement does not mean that the new car needs to be built from scratch. The new features can be easily incorporated in the old system without modifying the base attributes.

          Resilience to change also results in easier maintenance. This feature of object-oriented methodology is known as extensibility. The ability of a class to inherit features from another class also makes object-oriented programs more extensible. For the same reason, even during construction, parts of the system under development can be refined without any major changes to other parts.

  • Existence as Different Forms
          Using the object-oriented approach, objects can be made to respond differently to the same message. the response is decided based on the information or parameters provided with the message. This ability to react differently based on the information associated with the message is known as polymorphisum.


What the heck is ASP.NET Web API?


ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework. (Source MSDN)

To get started checkout an article from Mike Wasson - Getting Started with ASP.NET Web API 2 (C#)

What is Entity Framework?


Entity Framework is an Object Relational Mapping framework.

On high level, Object Relational Mapping framework automatically creates classes based on database tables (also known as Schema first approach) or it can also automatically generate necessary SQL to create database tables based on classes (also known as Code First approach).



There are three types of approach used in Entity Framework namely, 

  1. Schema First
  2. Model First
  3. Code First (Commonly used approach in development)

This should be sufficient to convince the interviewer question.

What are the new features of C# 6.0?


C# 6.0 is the latest version which ships with Visual Studio 2015. You to start learning the new features to update yourselves for many different reasons. C# 6.0 is not yet completed and Microsoft is releasing few features now and then. For interview point of view, just mentioned the following items and you should be satisfying the interviewer question.

Following are few features of C# 6.0

1. $ sign

The purpose for it is to simplify string based indexing. Its not some thing like current dynamic features of  C# since it internally uses regular indexing functionality. To understand lets consider following example:

  var col = new Dictionary()
            {
                // using inside the intializer
                $first = "Hassan"
            };

   //Assign value to member

   //the old way:
   col["first"] = "Hassan";
 
   // the new way
   col.$first = "Hassan";

2. Exception filters:

Exception filters are already supported in VB compiler but now they are coming into C#. exception filters lets you specify a condition for a catch block. the catch block gets executed only if the condition is satisfied, this one is my favorite feature, so let's look at an example:

            try
            {
                throw new Exception("Me");
            }
            catch (Exception ex) if (ex.Message == "You")
            {
                // this one will not execute.
            }
            catch (Exception ex) if (ex.Message == "Me")
            {
                // this one will execute
            }

3. await in catch and finally block:

As far as I know, no one know why in C# 5 using await keyword in catch and finally block was not available, any way its now possible to use though. this is great because often we want to perform I/O operation in order to log the exception reason in catch block or such things in finally block and they Need asynchrony.

            try
            {
                DoSomething();
            }
            catch (Exception)
            {
                await LogService.LogAsync(ex);
            }

4. Declaration expressions

This feature simply allows you to declare local variable in the middle of an expression. It is as simple as that but really destroys a pain. I have been doing a lot of asp.net web form projects in the past and this was my every day code:

long id;
if (!long.TryParse(Request.QureyString["Id"], out id))
{ }
which can be improved to this:
Hide   Copy Code
if (!long.TryParse(Request.QureyString["Id"], out long id))
{ }

The scoping rules for this kind of declaration is same as general scoping rules in C#.

5. using Static

This feature allows you to specify a particular type in a using statement after that all static members of that type will be accessible is subsequent code.

using System.Console;

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            //Use writeLine method of Console class
            //Without specifying the class name
            WriteLine("Hellow World");
        }
    }
}

6. Auto property initializer:

With C# 6 initialize auto properties just like a field at declaration place. The only thing to notice here is that this initialization dose not cause the setter function to be invoked internally. the value of backing field is set directly. so here is an example:

public class Person
    {
        // You can use this feature on both
        //getter only and setter / getter only properties

        public string FirstName { get; set; } = "Hassan";
        public string LastName { get; } = "Hashemi";
    }

7. Primary Constructor:

The main purpose for it is using constructor parameters for initialization. When declaring a primary constructor all other constructors must call the primary constructor using :this().
here is an example finally:

    //this is the primary constructor:
    class Person(string firstName, string lastName)
    {
        public string FirstName { get; set; } = firstName;
        public string LastName  { get; } = lastName;
    }

notice that declaration of primary constructor is at the top of the class.

8- Dictionary Initializer:

Some people believed that the old way of initiailzing dictionaries was dirty so the C# team dicided to make it cleaner, thanks to them. here is an example of the old way and new way:


            // the old way of initializing a dictionary
            Dictionary oldWay = new Dictionary()
            {
                { "Afghanistan", "Kabul" },
                { "United States", "Washington" },
                { "Some Country", "Some Capital city" }
            };

            // new way of initializing a dictionary
            Dictionary newWay = new Dictionary()
            {
                // Look at this!
                ["Afghanistan"] = "Kabul",
                ["Iran"] = "Tehran",
                ["India"] = "Delhi"
            };

Note: To play around and know more about C# 6.0 download Visual Studio 2015 click here

Recent Posts