Category: .net Technical


OOP Programming


1. What is OOP?

Object Oriented Programming

2. Write basic concepts of OOP?

(I personally think this is a bad question to ask, but people do ask this kind of questions.)

  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

3. What is a class?

A class is a definition of some thing, an instance (or object) is the actual thing of that definition. e.g. TV is a class, and my Samsung TV is my instance.

4. What is an object?

It is the actual instance of a class. e.g. Car is class, my Benz is an instance.

5. What is Encapsulation?

The Class can encapsulate the details of the logic.

6. What is Polymorphism?

class Employee { 
     public int getDiscount() { 
          return 5;
     }
}


class InternalEmployee : Employee { 
     public int getDiscount() { 
          return 10;
     }
 }

 class Contractor : Employee { 
      public int getDiscount() { 
          return 20;
     }
 }

Employee employee = new Employee();

employee.getDiscount(); // returns 5

Employee employee1 = new InternalEmployee();

employee1.getDiscount(); // returns 10

Employee employee2 = new ContractEmployee();

employee2.getDiscount(); // returns 20

As you see, although the variables have been declared with the same type Employee, and depends its actual initialisation, the same method will be executed differently.

So Polymorphism: Objects may behave differently depending on the “type” while keeping the same interface.

7. What is Inheritance?

One class can extend the features of the other Class, and the first class will be the sub class, usually it implies a more specific type of entity. e.g. Dog is subclass of Pet. Dog is more specific whereas Pet can contain some common features of Pet. This way when I create a class called Cat, I do not need to repeat everything Pet has already got.

9. Define a constructor?

Constructor is a method used to initialise of an object, and it gets invoked at the time of object creation.

The creation of object involves allocating the right size of the memory.

10. Define Destructor?

Destructor is a method which is automatically called when the object is destroyed. You can clean up things there if needed.

12. What is a virtual method?

Virtual method is a member method of class and its functionality can be overridden in its derived or subclass class.

13. What is overloading?

Same method name, but different number or type of parameters.

e.g.

void add(int a, int b);

void add(double a, double b);

void add(int a, int b, int c);

14. What is an abstract class?

  • An abstract class is a class which cannot be instantiated.
  • It will be inherited by specific type or class. (A type is a class, a class is a type)
  • An abstract class can contain only Abstract method.

15. What is a ternary operator?

condition ? expr1 : expr2 

If condition is true, expr1 is executed otherwise expr2 will be executed.

 

16. What is method overriding?

Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the super class by providing the same method name, same parameter and same return type.

17. What is an interface?

  • An interface is a contract.
  • An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

18.  What is exception handling?

Exception is an event that occurs during the execution of a program. Exceptions can be of any type – Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.

19. Difference between class and an object?

An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object. Class can have sub-classes, and an object doesn’t have sub-objects.

20. What is early and late binding?

Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.

JavaScript Technology


Post Thumbnail

The front end web technologies consist of HTML, CSS and JavaScript. JavaScript has been playing a major role in the evolution of the web development.

As you may have learnt jQuery which makes writing JavaScript much easier. Here are some popular JavaScript technologies you should at least have a play around.

If you learnt JavaScript well, you should be able to pick up any JavaScript framework in a couple of days, at least understand how it works.

And if you learnt one of a few JavaScript libraries, it is very easy to learn the others. It is really like if you learnt how to drive Toyota, and you can Drive BMW

TypeScript – which generates C#-alike code into JavaScript

  • It is developed by Microsoft, and it is superset of JavaScript. NOTE: TypeScript does not run inside browser directly, it needs to be translated to JacaScript first.
  • The Key features are static typing and class based OO programming
  • static typing means the type check is done at compile time. C#, Java are all static typing.
String test = "Hello";  // variable test statically typed as string
test = 7;               // this will cause compilation error as test can only be assigned with string.
                        // the advange is it is type safe.
  • dynamic typing means the type checking is done at the run time. JavaScript, PHP, Python are all dynamic typing.
test = "Hello";  // variable test dynamically typed as string.
test = 7;        // now it is typed as int which is OK in the language of dynamic typing. the downside is easily making mistakes.
  • TypeScript code can be trans-compiled into JavaScript.
  • Trans-compile means it can translate one source code to the other source code.
  • You can use classes and data types in TypeScript, and then TypeScript will creates the corresponding JavaScript. This process is called Trans-compile

NodeJS – Which runs JavaScript on the server

  • JavaScript usually runs inside the browser, but NodeJS can run JavaScript on the server, this means you can write JavaScript for the entire application both client and server
  • It can run as regular web server like IIS or Apache Web server.
  • Event based

ReactJs JavaScript Library

  • React is invented by Facebook.
  • It is a JavaScript language for building user interface in web browsers.
  • React Native is so far the most promising library for building cross platform native mobile Apps. <- this is getting very popular now
  • Virtual DOM concept. You interact with a virtual Domain Object Model of the browser.
  • There are so many jobs requiring you to at least know how React works.
class HelloMessage extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}
​
ReactDOM.render(<HelloMessage name="Jane" />, mountNode);

Vue.Js JavaScript Library

  • Also utilise the mechanism of virtual DOM
  • Provide reactive and composable view components
  • Simplicity and ease of use
  • Here is a simple example
<div id="journal">
  <input type="text" v-model="message">
  <div>{{message}}</div>
</div>

var journal = new Vue({
  el: '#journal',
  data: {
    message: 'HelloWorld'
  }
});

Angular 2

  • It is developed by Google
  • It is using Declarative code style
  • Two way of data binding. Changes flow between UI and model nicely.
  • Things can be divided into modules and easier to add modules.
  • It allows to create single pages web app easily.

AngularJS code to display a list of children

<div ng-controller="studentsController as studentsCrtl">
   <div ng-repeat="student in studentsCrtl.students">
​
       Name: <span class="name">{{student.name}}</span>
       Title: <span class="title">{{student.title}}</span>
​
   </div>
</div>

Ember.js

  • Amber allows developers to use future JavaScript standards and trans-compile them for use in browsers today.
  • Ember has plugin repository and well supported community.
  • Here is the ember js code at a glance. This will display the person’s name real time while user is typing it. Check out the syntax.
<div>
 <label>Name:</label>
 {{input type="text" value=name placeholder="Enter your name"}}
</div>
<div class="text">
 <h3>My name is {{name}} and I want to learn Ember!</h3>
</div>

Meteor.Js

  • You can develop the entire application with just JavaScript (with NodeJS)
  • Strong in real time applications
  • Easy to learn
  • Good support for mobile app
  • Here is a good example of Hello World https://www.mkyong.com/meteor/meteor-hello-world-example/

How to Use EF properly


EF is a ORM framework which make developer’s life easier (do not need to spend so much time on writing sql)

However, using EF is not a easy task. Here are some helpful tips while we use EF;

  1. Ensure we filter the data at the database level (ToList and ToArray filter inside memory and not at sql level.)
  2. Complicated query need to be separated into small chunks because EF are not good at solving that.
  3. when it comes to a complex query, we can use stored procedure to do it.
  4. EF track any changes of the objects inside. you can create some outside object.
  5. we need to slowly insert records into database
  6. add the right indexing is super important
  7. use sql profiler would be helpful.

 

Social Media


Categories



All Posts



Contact Info