Wednesday, September 17, 2014

Design Patterns

General reusable solutions to common problems in software design.
Creational:  Create objects while hiding the creation logic, rather than instantiate objects directly using new operator
Structural: are concerned with how classes and objects are composed to form larger structures. This is all bout class and object composiiton.
Behavioral: interaction/communication between objects.
  • Creational
    1. Singleton:  This pattern ensures that a class has only one instance. 
    2. Factory Method: In Factory pattern, we create object without exposing the creation logic
    3. Abstract Factory patterns acts a super-factory which creates other factories. This pattern is also called as Factory of factories. In Abstract Factory pattern an interface is responsible for creating a set of related objects, or dependent objects without specifying their concrete classes.
    4. Builder pattern builds a complex object by using a step by step approach. Builder interface defines the steps to build the final object. This builder is independent from the objects creation process. A class that is known as Director, controls the object creation process.
      Moreover, builder pattern describes a way to separate an object from its construction. The same construction method can create different representation of the object.
    5. Prototype pattern is used to create a duplicate object or clone of the current object to enhance performance. This pattern is used when creation of object is costly or complex.
  • Structural
    1. Adapter :  convert the interface of a class into another interface client expect Related patterns:  Repository, Strategy, Facade,  Adapter pattern:  convert the interface of a class into another interface client expect
    2. Bridge:
    3.  Adapter starts from letter 'A' - map with After and Bridge starts from letter 'B' map with Before. 
    4.  Now when its Adapter its always to deal with the situation when some implementation is already in place and but some kind of hack 
    5. or patch or connector to put in place to make it work, like the real (electric) adapter.
    6.   Where in bridge - its before hand - design should be such that interface and implementation both are independent 
    7.  so abstraction is covered at interface level but actual implementation differs based on condition or need.
  • Behavioral
  1. TemplateMethod:  Define the skeleton of an algorithm in an operation, deferring some steps toSubclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the Algorithm's Structure. 
  2. Strategy:There are common situations when classes differ only in their behavior. For this cases is a good idea to isolate the algorithms in separate classes in order to have the ability to select different algorithms at runtime. 
  3. Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Monday, September 15, 2014

Sunday, September 14, 2014

Complete Programming Language

1. Core language -  variables, functions, loops
2. Generics,Data structures and Collections.
2. Threading
3. Network reading and writing
4. Disk IO

Generics types allow code reuse with type safety
List, Queue, Stack, Hashset, SortedSet LinkedList, Dictionary, SortedDictionary, SortedList

Threadsafe : concurrent collections.
Disk IO:

A stream is a sequence of bytes that you can use to read from or write to a backing store.

  • Reading all the text file from disk
            File.ReadAllText(@"C:\temp\19.json"));
  • Reading large text file from Disk 
using (var sr = new StreamReader(file))
{
string line;
while ((line = sr.ReadLine()) != null)
{
    Console.WriteLine(line);
}
}




Wednesday, September 3, 2014

OO Design Principles

  1. Single responsibility: every object should have single responsibility. ( there should be never more than a single reason to change a class)
  2. Open/Closed Principle: software should be open for extension but closed for modification.
  3. Liskov Substitution Principle: states that sub types must be substitutable for their base types.
  4. Interface segregation principle:  clients should not be forced to depend on methods they do not use
  5. Dependency Inversion Principle:  High level modules should not depend on low level modules. Both should depend on abstractions.  Abstraction should not depend on details but details should depend on abstractions.
  6. Cohesion: within class strong cohesion
  7. Coupling: low coupling.
  8. Many small classes with distinct responsibilities result in more flexible design.
  9. Use small interfaces so you don't require classes to implement more than they need.
  10. Refactor large interfaces so they inherit smaller interfaces
  11. Don't Repeat Yourself principle: Every piece of knowledge must have single unambiguous representation in the system.
  12. Repetition in logic calls for abstraction and repetition in process calls for automation.
  13. Repetition breeds errors and waste.

An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class.

A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality.

Training

  1. Threading:     http://www.albahari.com/threading/
  2. http://www.dotnet-tricks.com/
  3. http://www.dotnetperls.com/

Tips

  1. Demo, Demo and Presentations
  2. Question or expand what are you are comfort at.

Moving to Developer role

  1. Learn Design Patterns
  2. TopCoder
  3. System and oo design solutions.
  4. Learn Language well
  5. Find the problem that is well needed for the business and solve extremely well
  6. Do code reviews to learn new designs and excellent coding skills.
  7. Always ask is this shippable code - is it qualitative, easy to debug, is it scalable,  can it be multi threaded?

Tuesday, September 2, 2014

Interview Questions - Strings

  • Given a string, return the string with the words reversed "I am good" -> "good am I" .List test cases and if you were crunched on time and only had time to test one test case, which would you pick
  • find the substring count from a string without string functions in java? Given String str = "abcdefghcde"; String find = "cde";   Count occurrences of cde in String str
  • How to replace the space in the string with "ABC" without using extra memory.. string may contain some extra memory. str = "i am chandu" -- str contation more memory...
  • str = "iABCamABCchandu"

My Found Bugs

  1. User exists in multiple partitions
  2. Renaming skydrive to onedrive

C# Threading

  1. Lock
  2. Monitor.Enter and Monitor.Exit
  3. Mutex is like a C# lock, but it can work across multiple processes
  4. A semaphore is like a nightclub: it has a certain capacity, enforced by a bouncer. Once it’s full, no more people can enter, and a queue builds up outside.
"A class is thread-safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code."

A program or method is thread-safe if it has no indeterminacy in the face of any multithreading scenario.

 Assemblies can be shared among multiple applications on the machine by registering them in global Assembly cache(GAC). GAC is a machine wide a local cache of assemblies maintained by the .NET Framework. We can register the assembly to global assembly cache by using gacutil command.
We can Navigate to the GAC directory, C:\winnt\Assembly in explore. In the tools menu select the cache properties; in the windows displayed you can set the memory limit in MB used by the GAC

Attributes allow you to add descriptions to classes, properties, and methods at design time that can then be examined at runtime via reflection.