Programming Index Cards

August 11, 2008

OOP Basics

Filed under: OOP — Tags: , — apcig @ 2:20 am

Polymorphism - appropriate method is called depending on the object type

Inheritance
- represents “Is A” relationship between classes.  Class A “is a” class B
- the ability to inherit properties and methods and extend the functionality of an existing class in a new one1

Composition
- represents “Has a” relationship between classes.  Class A “has a” class B

Encapsulation - used to hide information

Immutable - the data value cannot be changed

Arrays in .Net - cannot store more than 1 data type

Override - change behavior method for the derived class

Overload - having 2 or more methods with the same name in a class

Boxing - value to reference conversion -> heap

Unboxing - reference to value conversion -> stack

1Object-oriented programming with ActionScript 3.0

July 29, 2008

Abstract Class versus Interface

Filed under: OOP, c# — apcig @ 3:52 am

Abstract Class
An abstract class is a special kind of class that cannot be instantiated…
An abstract class is only to be sub-classed/inherited from…
Core identity/objects of same/similar type
Can have fields and constants defined

public abstract class Employee {
...
}

Interface
An entity that … has no implementation; it only has the signature, just the definition of the methods without the body.
Peripheral abilities/IMovable inherited by Human and Vehicle
If implementations, only share method signatures
No fields can be defined

public interface IEmployee {
...
}

Source

June 26, 2008

Accessibility Modifiers

Filed under: OOP, c#, programming — apcig @ 7:36 pm

public
- Access is not restricted.
- Allows the members to be globally accessible.

protected
- Access is limited to the containing class or types derived from the containing class.

internal
- Access is limited to the current assembly.
- Internal members are accessible only within files in the same assembly.

protected internal
- Access is limited to the current assembly or types derived from the containing class.

private
- Access is limited to the containing type.


sealed
- prevents inheritance

Sources: Accessibility Levels (MSDN), Difference between internal and private

Blog at WordPress.com.