Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.
An interface represents a contract, in that a class that implements an interface must implement every aspect of that interface exactly as it is defined.
With interfaces, you can define features as small groups of closely related members. You can develop enhanced implementations for your interfaces without jeopardizing existing code, thus minimizing compatibility problems. You can also add new features at any time by developing additional interfaces and implementations.
Although interface implementations can evolve, interfaces themselves cannot be changed once published. Changes to a published interface may break existing code. If you think of an interface as a contract, it is clear that both sides of the contract have a role to play. The publisher of an interface agrees never to change that interface, and the implementer agrees to implement the interface exactly as it was designed.
In previous versions of Visual Basic, you could consume interfaces but not create them directly. Now you can define true interfaces using the Interface statement
There are several other reasons why you might want to use interfaces instead of class inheritance:
• Interfaces are better suited to situations in which your applications require many possibly unrelated object types to provide certain functionality.
• Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces.
• Interfaces are better in situations in which you do not have to inherit implementation from a base class.
• Interfaces are useful when you cannot use class inheritance. For example, structures cannot inherit from classes, but they can implement interfaces.
Inheritance is a good choice when:
• Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.
• You can reuse code from the base classes.
• You need to apply the same class and methods to different data types.
• The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.
• You want to make global changes to derived classes by changing a base class.
Friday, November 6, 2009
Wednesday, October 21, 2009
OOP Concept
Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Examples of objects range from human beings (described by name, address, and so forth) to buildings and floors (whose properties can be described and managed) down to the little widgets on your computer desktop (such as buttons and scroll bars).
Object:-
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.
An object is an instance of class.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).
Class:-
A class is the blueprint from which individual objects are created.
class Test
{
}
The concept of Objects & Classes helps you hide your code implementation from the user of your class.
Inheritance:-
Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.
Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike.
it is possible to create a new class from an existing one and add new features to it. Thus inheritance provides a mechanism for class level re-usability.
class Base
{
}
class Derived : Base
{
}
Encapsulation:-
Encapsulation is process of keeping data and methods together inside objects.
public class Test
{
public Test()
{
}
protected double X;
protected double Y;
protected double Z;
public double GetABC()
{
}
}
Abstraction:-
An abstraction captures the essential features of an entity, suppressing unnecessary details. All instances of an abstraction share these common features. Abstraction helps us deal with complexity.
The implementation of an abstraction should be hidden from the rest of the system, or encapsulated. Objects have a public and a private side.
Polymorphism:-
The ability for the same method call to result in different behavior depending on the object through which the method is invoked is referred to as polymorphism.Polymorphism allows objects to be represented in multiple forms
The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them. Examples of objects range from human beings (described by name, address, and so forth) to buildings and floors (whose properties can be described and managed) down to the little widgets on your computer desktop (such as buttons and scroll bars).
Object:-
An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.
An object is an instance of class.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes).
Class:-
A class is the blueprint from which individual objects are created.
class Test
{
}
The concept of Objects & Classes helps you hide your code implementation from the user of your class.
Inheritance:-
Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.
Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike, RoadBike, and TandemBike.
it is possible to create a new class from an existing one and add new features to it. Thus inheritance provides a mechanism for class level re-usability.
class Base
{
}
class Derived : Base
{
}
Encapsulation:-
Encapsulation is process of keeping data and methods together inside objects.
public class Test
{
public Test()
{
}
protected double X;
protected double Y;
protected double Z;
public double GetABC()
{
}
}
Abstraction:-
An abstraction captures the essential features of an entity, suppressing unnecessary details. All instances of an abstraction share these common features. Abstraction helps us deal with complexity.
The implementation of an abstraction should be hidden from the rest of the system, or encapsulated. Objects have a public and a private side.
Polymorphism:-
The ability for the same method call to result in different behavior depending on the object through which the method is invoked is referred to as polymorphism.Polymorphism allows objects to be represented in multiple forms
Subscribe to:
Posts (Atom)