Posts

Showing posts from 2013

Singleton Pattern:[Creational]

Image
The Singleton Pattern ensures the class has only one instance and provides a global point of access it. Only one instance of the object to be created and shared between the clients. In singleton constructor is private, so other classes cannot instantiate it. Here instances & methods are static, so we can access it in global point. Ex: public sealed class ClassicSingleton {     //single instance     private static ClassicSingleton instance;     private static object syncRoot = new Object();       //private constructor     private ClassicSingleton() { }       public static ClassicSingleton Instance     {         get         {             if (instance == null)            ...

Abstract Factory:[Creational]

Image
  Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Creates an instance of several families of classes. Abstract Factory will be useful while create a family of objects that having same type of implementations. Note: Abstract Factory can be used while create an instance from family of objects [having lot of similarities] without changing the rules like Carnivore eats Herbivore.

Adapter pattern:[Structural]

Image
A class that would be useful to your application does not implement the interface that requires. Does not support multiple inheritances. Match interfaces of different classes. It is also known as “ Wrapper ”. Adapter is a wrapper that helps one object integrates with any other object's interface. Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Types: Class Adapter pattern Object Adapter pattern N OTE: Normally adapter pattern used in DataAccess layer to adapt the ADO.Net adapter classes like SQLAdapter.

Design Pattern

1. Design patterns are commonly defined as time-tested solutions to recurring design problems. It is a description or template for how to solve a problem that can be used in many different situations. It typically shows relationships and interactions between classes or objects without specifying the final application classes or objects that are involved. 2. Design patterns are not just about the design of objects but about the interaction between objects. Patterns are not concerned with algorithms or specific implementations. Originated by civil architect “Christopher Alexander” in 1977. Kent Beck and Ward Cunningham implemented in 1987. Gang of Four in 1994: Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. Advantages: Gives our profession in a shared language. Helps avoid re-inventing constantly. Provides a starting point for solution. Can speed production in a team. Generally improves system and application design. Gang of Four categorized in thr...

Development Principles (Software development methodology)

YAGNI (You aren't gonna need it)   do the simplest thing that could possibly work   KISS (Keep it simple, stupid) Simplicity is the ultimate sophistication   DRY (Don't repeat yourself) SOLID Principles:   Introduced by Robert C. Martin in the early 2000s. Helps to create a system that is easy to maintain and extend over time. It is typically used with test-driven development, and is part of an overall strategy of  agile  and  adaptive programming. S ingle responsibility principle: the notion that an object should have only a single responsibility. O pen/closed principle: the notion that “software entities … should be open for extension, but closed for modification”. L iskov substitution principle: the notion that “objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program”. I nterface segregation principle: the not...

.Net Collections

The  System.Collections namespace contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hash tables and dictionaries. Array list: Implements the IList interface using an array whose size is dynamically increased as required. Dictionary Base: Provides the abstract (MustInherit in Visual Basic) base class for a strongly typed collection of key-and-value pairs. Dictionary is a Generic type. So we can get type safety with Dictionary. Hash table: Represents a collection of key-and-value pairs that are organized based on the hash code of the key. A key cannot be a null reference (Nothing in Visual Basic), but a value can be. Hashtable is not a Generic type. So we can’t get type safety with Hashtable. Hashtable is thread safe. Queue: Represents a first-in, first-out collection of objects. Queues are useful for storing messages in the order they were received for sequential processing. Stack: ...

Angular JS – Part 4

Services: Syntax: module.service( 'serviceName', function ); Result: When declaring serviceName as an injectable argument you will be provided with an instance of the function. In other words new FunctionYouPassedToService(). Factories: Syntax: module.factory( 'factoryName', function ); Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory. Providers: Syntax: module.provider( 'providerName', function ); Result: When declaring providerName as an injectable argument you will be provided with new ProviderFunction().$get(). The constructor function is instantiated before the $get method is called - ProviderFunction is the function reference passed to module.provider.

Angular JS – Part 3 - Unit tests

Unit tests in Angular using Jasmin How to pass the mock dependencies to Angular Tests Karma Server is used to run Node Test files End to End tests. Browser() function is the special function used in end to end tests To troubleshoot e2e test, use pause() function. It will pause the action on browser.

Angular JS – Part 2

Angular Routing Services and Directives: Routing Services: $route - $routeProvider is used to map the URL with template + assigned controller. (specially for SPAs). Methods: when(), otherwise(redirectTo:), current, params, pathParams, reload(). Also we can use resolve() to decide before load template. $routeParams – Used to pass the parameters via URL $location –Use to enable html5 routing. Can get the URL informations Eg. absUrl, protocol, port, host, path, search, hash, url. Replace() method will not keep URL history. Directives: Uses of Directives: Create custom element, custom event, observe and react to changes Use eventApp.dirctive("directiveName",function(){ return {restrict: 'E', template: "<input>"}}); Can restrict the directive to how should use. E(element), C(class), A(attribute), M(comment). Instead of template HTML text, the URL can be used. Use" replace: true" to replace the element name to html i...

Angular JS – Part 1

Angular JS is used for MV* (Controller, Presenter, ViewModel) frameworks. Can use JQuery/Zepto. Angular is comprehensive. Partial Templates Updating the data Routing Testable Extends HTML vocabulary Forward Thinking Web components Object.Observe Angular Architecture: Supports two-way binding Dirty Checking Dependency Injection Angular Components: Controllers Views/Directives Directive – Use to extend the HTML. Services Basics: "ng_controller" attribute is used to specify the controller part in HTML. "$scope" is a special field using by Angular, which will pass the values to controller. "Angular Seed" is zip file, while will work as starting point of the application.[Skeleton of the angular application]. Download this for quick bootstrap. Controller create Scope(primary responsibility) which have two way communication with Views. Views use the values in scope and the events use the functions...

Backbone JS

Provides models with key-value binding and custom events, collections, and connects it all to your existing API over a RESTful JSON interface. Used for SPA(Single page applications) like Gmail, Facebook, Twitter. Client Side JS: Routers Models Views Collection Advantages: Fast Highly interactive Scalable Disadvantages: Cannot be indexed by search engines(without extra work) Difficult to test Security issues( security must be enforce by the server) Required Dependencies: Underscore.js (Functional support for Javascript) JQuery/zerto (zepto is only for modern browsers, DOM manipulation & AJAX) Understanding: Backbone.Model is used to create object. Use Get(), Set(0 method to change property values. Need to create a model Object by extending Backbone.Model, and need to pass it to a view that extended from Backbone.View. Models: Models hold the application data. The Purpose of models Models form the core of the applic...

Calculate Code Metrics - Way to assert your code

Calculate Code Metrics: Whenever we write any code, we will refactor and optimize the code for better performance. Really we cannot assert our code is optimized or not, since we just did what we know about code metrics.  Visual Studio provides an option to assert our code metrics. In Solution explorer, right click on solution or project file gives you the “ Calculate Code Metrics ” option.  You can check and refactor your code by using this option. Code metrics is a set of software measures that provide developers better insight into the code they are developing. By taking advantage of code metrics, developers can understand which types and/or methods should be reworked or more thoroughly tested. Development teams can identify potential risks, understand the current state of a project, and track progress during software development. Maintainability Index:  Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A ...

BDD - Acceptance Test Driven Development

Image
Acceptance Test Driven Development What is BDD: BDD is an agile software development technique that encourages collaboration between developers, QA, and non-technical or business participants in a software project. It's more about business specifications than about tests. You write a specification for a story and verify whether the specs work as expected. The main features of BDD development are outlined below:   A testable story (it should be the smallest unit that fits in an iteration) The title should describe an activity The narrative should include a role, a feature, and a benefit The scenario title should say what's different The scenario should be described in terms of Givens, Events, and Outcomes The givens should define all of, and no more than, the required context The event should describe the feature   Advantage of BDD:   The first advantage is that this domain language is usable/understandable by domain experts as well. Given that you e...

Get inserted or deleted records in SQL - OUTPUT Clause

In SQL, how we identify the last inserted or deleted records? We’ve used @@identity to get the last inserted records identity value. This will not be sufficient while insert lot of records in same time. To solve that, we have OUTPUT clause to get the inserted/deleted data information. Especially this OUTPUT clause is very useful while using MERGE clause. Since this is the only way to get inserted/deleted records in TARGET table. OUTPUT Clause: Returns information from, or expressions based on, each row affected by an INSERT, UPDATE, DELETE, or MERGE statement. These results can be returned to the processing application for use in such things as confirmation messages, archiving, and other such application requirements. The results can also be inserted into a table or table variable. Additionally, you can capture the results of an OUTPUT clause in a nested INSERT, UPDATE, DELETE, or MERGE statement, and insert those results into a target table or view. Ref:   http://...

Tricks to eliminate GROUP BY problems in SQL

Most of us having trouble with using GROUP BY clause in SQL. GROUP BY class is painful, because we cannot select the columns other than the columns used in GROUP BY. We have another concept to get rid of GROUP BY clause problems. The OVER ( PARTITION BY column_name) will work like a GROUP BY clause, and we can do the same with this clause without any limitation of GROUP BY.   Can we use any aggregate function without using GROUP BY? Yes. We can. Please execute the below SQL query sample to know about OVER ( PARTITION BY … ) class. Sample: IF OBJECT_ID ( 'tempdb..#student_details' ) IS NOT NULL       DROP TABLE #student_details       CREATE TABLE #student_details (        student_id UNIQUEIDENTIFIER       , student_ident INT IDENTITY ( 1 , 1 ) PRIMARY KEY       , student_name VARCHAR ( 15 ) ) GO DECLARE @du...