1. What is Abstract Class? When it is used? Is there any alternative ?
  2. What is Static Class? Difference between Abstract and static class?
  3. Can Class be private?
  4. What is Singleton Class? Give an example where you needed to create singleton class in your application.
  5. How In MVC application, a view know which controller to go to?

7 thoughts on “5Questions

  1. Answer2: Static class is class which can’t be instantiated. Only static members are allowed inside static class. Main difference between Abstract and static class is, Abstract class is more of like blue print providing the base for derivative classes while static class serves more of providing utility to other classes or method call. One common similarities is, neither of them can be instantiated.


  2. Answer 1: An abstract is class which must be derived in other classes, it provides base functionality plus some other declarations which are implemented in derive class. An abstract is class like others, so it can have fields,properties,methods,events and even static members except it does not allow to create an instance of. As in alternative, interface+extension method can serve the purpose. But it depends on the need and varies team to team.


  3. Answer 3: A class “CAN NOT” be private, Default accessibility level is public. Only public and internal access modifiers are allowed. If you try to use private or any other access modifiers than what are allowed, it throws compile time error.
    Eg. “Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal”


  4. Answer 4: A singleton class is design pattern which implies it is not solely tied to .Net. A singleton class is class which is instantiated only once by itself until the application is closed. To give ruff idea on where I needed to implement singleton class is the situation where we didn’t needed to have more than one object of same type flowing all around the application and causing memory flow issue. A perfect example could be, logging,caching,load balancer…things like this never change regardless of the state of the application. So it is always advisable to just have one instance created.
    One can argue to use static class instead but it brings dependency injection headache which is easily solved by using singleton class.


  5. Answer 5: In classical ASP.Net era, designer page and code behind class are tightly coupled , in other words, for every actions of web controls, there would be method available to reach to inside code behind file. This “tightly coupled” concept is forbidden in MVC architecture but still view need to communicate to controller and vice versa. As per my understanding, the concept of delegate has not gone away in MVC rather it is polished in better way. In short, a delegate still plays vital role to connect to view action with controller method. Also, by definition “Routing configuration” provides surface level understanding on how “action” verb used with controller actually goes to “view” (action says a method inside controller file to match with view name) Eg. If action verb = “Index” inside “Controller name = Home”, there is matching “Index.cshtml” found.


  6. 02-29-2016
    Question 1: What’s the difference between Html.TextBox and Html.TextBoxFor?
    Answer: Html.TextBox is not strongly typed and hence it doesn’t require strongly typed view. Html.TextBoxFor is for strongly typed view and also provide compile time checking. But both produce the same HTML.

    Question 2: List few of html helpers class.
    Answer: Html.TextBox, Html.Lable, Html.Password, Html.TextArea, Html.Hidden, Html.ActionLink, Html.DropDownList, Html.RadioButtonList, Html.CheckBoxList, Html.ListBox

    Question 3: How to use DisplayAttribute, DisplayFormat and ScaffoldColumn (control column display or not)?


    1. Answer3: “System.ComponentModel.DataAnnotations” namespace provides attribute classes to define metadata for MVC and asp.net DataControls. What it does is, when you decorate property of model class with any of the above attributes , it performs specific actions on view. Eg. DisplayAttribute is used to when you want to control on how property name should be displayed on view(eg. as “FullName” or “Full Name”). DisplayFormat allows applying different formats for property value(Eg. 12/12/2012 or 345.54) and Scaffold attribute is bit tricky, its main purpose is to show or hide the property but it only works when “DisplayForModel” helper class is used in html file to display property name and its value.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s