Thursday, 6 September 2012

FAQs -II - OOPs

What is software architecture?

Software Architecture is defined to be the rules, heuristics and patterns governing.

What are steps to follow when architecting a solution? 

  • Partitioning the problem and the system to be built into discrete pieces
  • Techniques used to create interfaces between these pieces
  • Techniques used to manage overall structure and flow
  • Techniques used to interface the system to its environment
  • Appropriate use of development and delivery approaches, techniques and tools.

Why is Architecture Important?

Architecture is important because it:
  • Controls complexity
  • Enforces best practices
  • Gives consistency and uniformity
  • Increases predictability
  • Enables re-use.

What are various principles to design a class

Five principles that should be followed when designing a class,
  •  SRP - The Single Responsibility Principle - A class should have one, and only one, reason to change.
  • OCP - The Open Closed Principle - You should be able to extend a classes behavior, without modifying it.
  • LSP - The Liskov Substitution Principle- Derived classes must be substitutable for their base classes.
  • DIP - The Dependency Inversion Principle- Depend on abstractions, not on concretions.
  • ISP - The Interface Segregation Principle- Make fine grained interfaces that are client specific.

What is the best way to design a sytem?

In software world the concept of dividing and conquering is always recommended, if you start analyzing a full system at the start, you will find it harder to manage. So the better approach is to identify the module of the system first and then dig deep in to each module separately to seek out classes.

What are four Pillars of OOP?
 

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


What is Encapsulation?


  • Encapsulation is Information Hiding.
  • You hide the internal implementation and just expose the contract to the outside world.
  • Encapsulation is achieved through Association , Aggregation and Composition.
  • Interfaces are best examples of encapsulation.
 
 

Describe Association, Aggregation and Composition


  • Association - Is A relationship Animal Cat
  • Aggregation - HAS A relationship School Principal
  • Composition - Special type of aggregation.Book and Chapters
  • If you dispose Chapters , book won't exist.
  • Composition is used in Collections. Key -Value pairs.


What is Abstraction?

  •  Simplification of a system can be said to be abstraction.
  • abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects.
  • It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.
  

What is Polymorphism?

  •  Reducing the complexities of a system.
  • Polymorphsim is generalization.
 
 

What is abstract class?


  • Abstract classes, which declared with the abstract keyword, cannot be instantiated.
  •  It can only be used as a super-class for other classes that extend the abstract class.
  • Abstract class is the concept and implementation gets completed when it is being realized by a subclass.
  • In addition to this a class can inherit only from one abstract class (but a class may implement many interfaces) and must override all its abstract methods/ properties and may override virtual methods/ properties.
 
 

What is an interface?


Interface can be used to define a generic template and then one or more abstract classes to define partial implementations of the interface.
Interfaces just specify the method declaration (implicitly public and abstract) and can contain properties (which are also implicitly public and abstract).
Interface definition begins with the keyword interface. An interface like that of an abstract class cannot be instantiated.
 
 

Difference between Class and Interface?


  • Class and an interface are two different types (conceptually).
  • Theoretically a class emphasis the idea of encapsulation, while an interface emphasis the idea of abstraction (by suppressing the details of the implementation).
  • The two poses a clear separation from one to another.
  • Therefore it is very difficult or rather impossible to have an effective meaningful comparison between the two, but it is very useful and also meaningful to have a comparison between an interface and an abstract class.
 

Differences between Interface and abstract class


  • Interface definition begins with a keyword interface so it is of type interface
  • Abstract classes are declared with the abstract keyword so it is of type class
  • Interface has no implementation, but they have to be implemented.
  • Abstract class’s methods can have implementations and they have to be extended.
  • Interfaces can only have method declaration (implicitly public and abstract) and fields (implicitly public static)
  • Abstract class’s methods can’t have implementation only when declared abstract.
  • Interface can inherit more than one interfaces
  • Abstract class can implement more than one interfaces, but can inherit only one class
  • Abstract class must override all abstract method and may override virtual methods
  • Interface can be used when the implementation is changing
  • Abstract class can be used to provide some default behavior for a base class.
  • Interface makes implementation interchangeable
  • Interface increase security by hiding the implementation
  • Abstract class can be used when implementing framework
  • Abstract classes are an excellent way to create planned inheritance hierarchies and also to use as non-leaf classes in class hierarchies.

What is Inheritance?


Ability of a new class to be created, from an existing class by extending it, is called inheritance.
 

What is method Overloading?


The method overloading is the ability to define several methods all with the same name but different signature and return type.
Ex : + ; operator overloading
 

What is method overriding?

Changing the implementation.
Ex : ToString () method overriding

What is an extender class?


An extender class allows you to extend the functionality of an existing control. It is used in Windows forms applications to add properties to controls.


What is implementation and interface inheritance?


When a class (type) is derived from another class(type) such that it inherits all the members of the base type it is Implementation Inheritance.

When a type (class or a struct) inherits only the signatures of the functions from another type it is Interface Inheritance.

In general Classes can be derived from another class, hence support Implementation inheritance. At the same time Classes can also be derived from one or more interfaces. Hence they support Interface inheritance.
 

No comments:

Post a Comment