OOPS

Software Design Fundamentals

Software Design Fundamentals:

Let us explain and understand the following Design Terms:

1. Design Principle

2. Design Pattern

3. Design Characteristics

4. Design Paradigm

5. Design Pattern Language

6. Design Standard

7. Best Practice

Design Principle:

Why method calling through interfaces are slower than calling from abstract classes?

what is a sealed class

in

Factory Method Explained

Intent
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. [GoF, p107]
Defining a "virtual" constructor.
The new operator considered harmful.

Problem
A framework needs to standardize the architectural for a range of applications, but allow for individual applications to define their own domain objects and provide for their instantiation.

Discription

Features of An Abstract Class in C#

in

Abstract classes have the following features:

1. An abstract class cannot be instantiated.
2. An abstract class may contain abstract methods and accessors.
3. A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
4. It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited.

Abstract Methods have the following features:
1. An abstract method is implicitly a virtual method.

Interfaces in C#

in

An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface, as shown in the following example:

interface IExampleInterface
{
void ExampleMethod();
}

class ImplementationClass : IExampleInterface
{
// Explicit interface member implementation:
void IExampleInterface.ExampleMethod()
{
// Method implementation.
}

static void Main()
{
// Declare an interface instance.
IExampleInterface obj = new ImplementationClass();

Object-Oriented Terminology

in

Abstract class
Defines the methods and common attributes of a set of classes that are conceptually similar. Abstract classes are never instantiated.

Attribute
Data associated with an object (also called a data member).

Class
Blueprint of an objectdefines the methods and data of an object of its type.

Constructor
Procedure that is invoked when an object is created.

Derived class
A class that is specialized from a base class. Contains all of the attributes and methods of the base class but may also contain other attributes or different method implementations.

Some more Design Tips

Abstraction is your friend: A software design is a complex thing, especially, if you do not use abstraction to good effect. The design should be done at various levels of abstraction. At higher levels, you visualize the system as a small number of big components while abstracting away the details of what is inside each component. Once you have a good definition of what each of those components represent and how they interact with each other, you can move to the next lower level of abstraction.

Design Tips: Do Not Allow Inheritance Of Custom Attributes

Attribute classes should inherit directly from System.Attribute and should therefore be protected from further inheritance.

Error Handling Design Tips

in

Here are some Design Tips on Error Handling or Exception Handling:

1. ArgumentException should be used if invalid parameters are passed.
2. Catch block should log exceptions to event log
3. Directory.GetFiles() method requires try/catch block
4. Do not create methods that throw System.SystemException
5. Do not create methods that throw System.Runtime.InteropServices.ExternalException
6. Do not create methods that throw System.NullReferenceException
7. Do not create methods that throw System.Exception
8. Do not create methods that throw IndexOutOfRangeException