A beginner's guide to Object Orientation
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.
One of the principal advantages of object-oriented programming techniques over procedural programming techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify.
The first step in OOP is to identify all the objects you want to manipulate and how they relate to each other, an exercise often known as data modeling. Once you've identified an object, you generalize it as a class of objects and define the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. A real instance of a class is called an "object" or, in some environments, an "instance of a class." The object or class instance is what you run in the computer. Its methods provide computer instructions and the class object characteristics provide relevant data. You communicate with objects - and they communicate with each other - with well-defined interfaces called messages.
Let us see characteristics of Object-oriented programming in details:-
In structured programming a problem is approached by dividing it into functions .Unlike this ,in object –oriented the problem is divided into objects.Thinking in terms of objects rather than functions makes the designing of program easier. In an object-oriented programming language, objects and object interactions are the basic elements of design.Every object has both state (data) and behavior (operations on data). For example we can treat employees as objects in Payroll system or computers in a network.
A class defines the abstract characteristics of a thing, including the thing's characteristics (its attributes or properties) and the things it can do . For example, the class Dog would consist of traits shared by all dogs, for example breed, fur color, and the ability to bark. Classes provide modularity and structure in an object-oriented computer program. A class should typically be recognizable to a non-programmer familiar with the problem domain, meaning that the characteristics of the class should make sense in context. Also, the code for a class should be relatively self-contained. Collectively, the properties and methods defined by a class are called members.
A program can have more than one object of the same kind. The program that models water usage, for example, might have several Faucets and WaterPipes and perhaps a handful of Appliances and Users. Objects of the same kind are said to belong to the same class. All members of a class are able to perform the same methods and have matching sets of instance variables. They also share a common definition; each kind of object is defined just once.
The process by which an object sends data to another object or asks the other object to invoke a method.
The term method refers to a piece of code that is exclusively associated either with a class or with an object .Like a procedure in procedural programming languages, a method usually consists of a sequence of statements to perform an action, a set of input parameters to customize those actions, and possibly an output value (called return value) of some kind. The purpose of methods is to provide a mechanism for accessing the private data stored in an object or a class.
It is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time In object-oriented programming abstraction is the facility to define objects that represent abstract that can perform work, report on and change their state, and communicate with other objects in the system. The term encapsulation refers to the hiding of state details, but extending the concept of data type from earlier programming languages to associate behavior most strongly with the data, and standardizing the way that different data types interact, is the beginning of abstraction. When abstraction proceeds into the operations defined, enabling objects of different types to be substituted, it is called polymorphism. When it proceeds in the opposite direction, inside the types or classes, structuring them to simplify a complex set of relationships, it is called inheritance
Inheritance is a way to form new classes using classes that have already been defined. The new classes, known as derived classes, take over (or inherit) attributes and behaviour of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse of existing code with little or no modification.
Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects. For instance, a "fruit" is a generalization of "apple", "orange", "mango" and many others. One can consider fruit to be an abstraction of apple, orange, etc. Conversely, since apples are fruit (i.e. an apple is-a fruit), apples may naturally inherit all the properties common to all fruit, such as being a fleshy container for the seed of a plant.
An advantage of inheritance is that modules with sufficiently similar interfaces can share a lot of code, reducing the complexity of the program. Inheritance therefore has another view, a dual, called polymorphism, which describes many pieces of code being controlled by shared control code.
Inheritance is typically accomplished either by overriding (replacing) one or more methods exposed by ancestor, or by adding new methods to those exposed by an ancestor.
Object-oriented programming languages permit you to base a new class definition on a class already defined. The base class is called a superclass; the new class is its subclass. The subclass definition specifies only how it differs from the superclass; everything else is taken to be the same.
Nothing is copied from superclass to subclass. Instead, the two classes are connected so that the subclass inherits all the methods and instance variables of its superclass.
Encapsulation is the principle of information hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed. Protecting a design decision involves providing a stable interface which shields the remainder of the program from the implementation .In modern programming languages, the principle of information hiding manifests itself in a number of ways, including encapsulation and polymorphism. In object-oriented programming, information hiding reduces software development risk by shifting the code's dependency on an uncertain implementation onto a well-defined interface. Clients of the interface perform operations purely through the interface so if the implementation changes, the clients do not have to change.
To design effectively at any level of abstraction, you need to be able to leave details of implementation behind and think in terms of units that group those details under a common interface. For a programming unit to be truly effective, the barrier between interface and implementation must be absolute. The interface must encapsulate the implementation--hide it from other parts of the program. Encapsulation protects an implementation from unintended actions and inadvertent access. Members are often specified as public, protected and private, determining whether they are available to all classes, sub-classes or only the defining class.
This ability of different objects to respond, each in its own way, to identical messages is called polymorphism.
Polymorphism results from the fact that every class lives in its own name space. The names assigned within a class definition won't conflict with names assigned anywhere outside it. This is true both of the instance variables in an object's data structure and of the object's methods.Method names are also protected. Unlike the names of C functions, method names aren't global symbols. The name of a method in one class can't conflict with method names in other classes; two very different classes could implement identically named methods.
The main benefit of polymorphism is that it simplifies the programming interface. It permits conventions to be established that can be reused in class after class. Instead of inventing a new name for each new function you add to a program, the same names can be reused. The programming interface can be described as a set of abstract behaviors, quite apart from the classes that implement them.
A principal goal of object-oriented programming is to make the code you write as reusable as possible to have it serve many different situations and applications so that you can avoid reimplementing, even if in only slightly different form, something that's already been done. One class is completed and tested it can be distributed to other programmers for use in their own programs .This is called as reusability.
Re: A beginner's guide to Object Orientation
is there any basic link between abstraction and encapsulation
Re: A beginner's guide to Object Orientation
i want to learn more about programming.
Re: A beginner's guide to Object Orientation
Object-oriented programming is revolutionizing the world of software development. This revised and adapted roadmap is advised to adviser the abounding who are admiring to the ability and versatility of OOP, but unfamiliar with its core logic and confusing terminology.
|All times are GMT +5.5. The time now is 02:32.|