Вы находитесь на странице: 1из 4

Agenda

OOPS Part - I

      

Why OOPS ? What is OOPS ? Object Class Access Specifiers Data Abstraction Data Encapsulation Inheritance

Compilation

Why OOPS?

What is OOPS?

Classes and Objects

DEV200

Why Objects?
 

What is an Object?
    

Modularity - large software projects can be split up in smaller pieces. Reusability - Programs can be assembled from pre-written software components. Extensibility - New software components can be written or developed from existing ones.

Tangible Things as a car, printer, ... Roles as employee, boss, ... Incidents as flight, overflow, ... Interactions as contract, sale, ... Specifications as colour, shape,

What is an Object?


What is an Object?
Object = Data + Methods or to say the same differently: An object has the responsibility to know and the responsibility to do.

an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain. Or An "object" is anything to which a concept applies.

Types of Classes
     

Abstract Class
  

Concrete Class or Class Abstract Class Static Class Partial Class Sealed Class Nested Class

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

DEV200

Static Class
   

Access Specifiers

They only contain static members. They cannot be instantiated. They are sealed. They cannot contain instance Constructors

Access Specifiers
Given a class named "list" with a variable named "size"  public int size;


Abstraction vs Encapsulation


everyone can see size 

private int size;




only list objects can see size, default is private

protected int size;




list objects and objects derived from list can see size

Abstraction is the representation of the essential features of an object. These are encapsulated into an abstract data type. Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.

internal and protected internal

Encapsulation

What is an inheritance?


Building a new class by reusing everything in an existing class. Subclasses can add to their base class's list of methods and fields, and can also replace inherited methods.
Animal Fish

Mammal

DEV200

Declaring an Inherited Class


public class stack : list {}
The new stack class is a subclass of the list class

Replacing Inherited Methods


inside the list class:
public virtual void addvalue (int val) public int maxvalue ()

All fields marked as "protected" or "public". "private" fields are only visible to the class that declared them "protected" fields are only visible to the class that declared them, and any subclasses All public and protected methods.

inside the stack class:


public override void addvalue (int val)
 

So... now objects of type stack have their own unique addvalue function. maxvalue is inherited and can not be replaced.

Constructors Are Not Inherited





Types of Inheritance
     

Subclasses don't inherit their parent's constructors


but remember that constructors are optional

Subclasses can call their parent's constructor:

public stack (int size) : base (size) { any extra work for constructing a stack method's body might be empty }

Single Level Multi Level Multiple Hybrid Hierarchical Multi Path

Resources from Microsoft Press


MICROSOFT .NET FRAMEWORK

Discussion

For more information please visit the TechEd Bookshop. www.microsoft.com/mspress

DEV200

Вам также может понравиться