Sunteți pe pagina 1din 13

Object Oriented Programming Paradigm

OOP is a better way of solving computer problems compared to a procedural programming language such as C. OOP uses classes which contain members (variables) and methods (functions). OOP uses a modular type of programming structure.

OOP is a type of programming in which programmers define not only the data type of a data structure, but also the types of operations that can be applied to the data structure. In this way, the data structure becomes an object that includes both data and functions. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects.

One of the main advantages of object-oriented programming over procedural programming 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 fro existing objects. This makes object-oriented programs easier to modify.

In order to use the OOP paradigm, a programmer can use one of the programming languages such as C++, Java or Smalltalk.

Thus, C++ supports styles of programming that rely on fairly direct manipulation of hardware resources to deliver a high degree of efficiency plus higher-level styles of programming that rely on user-defined types to provide a model of data and computation that is closer to a human’s view of the task being performed by a computer. These higher-level styles of programming are often called data abstraction, object-oriented programming, and generic programming.

A way of viewing world agents:-

In an object oriented programming every world agent are objects i.e OOP uses an approach of treating a real world agent as an object. Object – oriented programming organizes a program around its data( that is , objects) and a set of well defined interface to that data.

Consider an example sending flowers to the friend the friend who lives in different city. But I can’t deliver them myself. So I use my locat florist. I tell my florist(named ram) the address for my friend. How much I want to spend and the type of flowers, I wish to send . ram contacts a florist in my friend’s city. Who

arranges the flowers, then contacts a driver, who delivers the flowers. If we start to think about it, there may even be other people involved in this transaction. There is the flower grower, perhaps somebody in charge of arrangements, and so on. Here in this work, every people involved are the objects (I.e myself, my friend, the florist, the florist in my friends city, the driver, the flower arranger, and the grower). Each agent has a part to play , and the result is produced when all work together in the solution of a problem.

Copy with complexity

When computing was in its childhood, large programs are written in assemble language by a single individual. They would not be designed and developed as today’s standards. At that time, when program became more complex, programmers found it difficult to remember all the information they needed to know in order to develop or debug their software. Which values were contained in what registers? Did a new identifier name conflict with any previously defined name? what variables needed to be initialized before control could be transferred to another section of code? The invention or development of the high level language. (such as procedural and object oriented tries to solve such complexity of the traditional programming language.

Computation as Simulation

The oop view of computation is similar to creating a universe of interacting computing objects. It is also very similar to a style of simulation called discrete event driven simulation. In discrete event driven simulation the user creates computer models of the various elements of the simulation, describes how they will interact with one another and sets them moving. This is almost identical to the object oriented program, in which the user describes what the various entities in the universe for the programs are and how they will interact with one another, and finally sets them in motion. Thus in object oriented programming the computation is simulation.

Interface and implementation

In software we use the terms interface and implementation to describe the distinction between that what aspects of a task and the how features, between the outside view and the inside view. An interface describes what a system is designed to do. This is the view that users of the abstraction must understand. The interface says nothing about how the assigned task is being performed. So to work, an interface is matched with an implementation that completes the abstraction. The designers of an engine will deal with the interface to the transmission, while the designers of the transmission must complete an implementation of this interface.

Similarly, a key step along the path to developing complex computer systems will be the division of a task into component parts. These parts can then be developed by different members of a team. Each component will have two faces: the interface that it show to the outside world and an implementation that it uses to fulfill the requirements of the interface.

The division between interface and implementation not only makes it easier to understand a design at a high level but also makes it.d

The nonlinear behavior of complexity

When the project became large and complex, an interesting phenomenon can be observed. A task that would task one programmer two months to perform could not be accomplished by two programmers working for month. The reason for this non- linear behavior was complexity- in particular, the interconnection between software components ware complicated, and large quantities of information had to be communicated among the various members of the programming team.

Abstraction Mechanisms

Abstraction denotes the essential characteristic of an object the distinguishes it from all other kinds of object and provides conceptual boundaries, relative to the perspective view of the user.

Focuses on the outside view of an object and serve to separate an objects behavior from its implementation.

Focuses upon the essential characteristic of some object , relative to the perspective of the viewer.

Diff b/w procedural structural language & oops

Conventional programming approach

Object oriented programming lang

It divide the problem into function

It divides the problem into number of entities called object

It lays more emphasis on function

It lays more emphasis on data rather than functions.

It follows a top down approach

It follow a bottom up approach

It is used for designing medium sized application

It is used for designing large and complex application

Functions communicate with each other by passing parameters

Objects communicate with each other by passing messages.

It uses the concept of procedure abstraction

Is uses the concept of data abstraction.

It does not support reusability

It supports reusability of code

Difficult to understand the structure and working and of large and complex application

Easy to understand the structure and working of the complex application.

Programming languages like c, pascal,

Programming lang like c++,java,c#

The difference between the development of individual projects and of more sizable software system is often described as programming in the small versus programming in the large.

Programming in the large:

In software development, programming in the large can involve programming by larger groups of people or by smaller groups over longer time periods. Either of these conditions will result in large, and hence complicated, programs that can be challenging for maintainers to understand.

With programming in the large, coding managers place emphasis on partitioning work into modules with precisely specified interactions. This requires careful planning and careful documentation.

With programming in the large program changes can become difficult . if a change operates across module boundaries, the work of many people may need re-doing. Because of this, one goal of programming in the large involves setting up modules that will not need altering in the event of probable changes. This is achieved by designing modules so they have high cohesion and loose coupling.

Programming in the large requires abstraction creating skills. Until a module becomes implemented it remains an abstraction. Taken together, the abstractions should create an architecture unlikely to need change. They should define interactions that have precision and demonstrable correctness.

Programming in the large requires management skills. The process of building abstractions aims not just to describe something that can work but also to direct the efforts of people who will make it work.

The concept was introduced by frank deremer and hans kron In their 1975 paper “programming – in- the large versus programming in-the-small”

Programming in the small

In software development, programming in the small describes the activity of writing a small program. Small programs are typified by being small in terms of their source code size, are easy to specify, quick to code and typically perform one task or a few very closely related tasks very well.

Programming in the small can involve programming by individuals or small groups over short time periods and may involves less formal practices tools and programming language(e.g the selection of a loosely typed scripting language in preference to a strictly typed programming language.) programming in the small can also describe an approach to making a prototype software or where rapid application development is more important than stability or correctness.

In computer science terms, programming in the small deals with short lived programmatic behavior, often executed as a single ACID transaction and which allows access to local logic and resources such a files, database, etc.

Why separate interface from Implementation?

An interface declares a set of operations. An object typed by that interface guarantees to support those operations. An implementation, on the other hand, defines how the object supports those operations, that is an implementation defines the representation of the object and a set of algorithms implementing the operations declared in the interface.

Separating interface from implementation is desirable for achieving flexible, extensible, portable and modular software. If client code depends only on the interface to an object and not on the object’s implementation, a different implementation can be substituted and the client code continues to work, without change or recompilation. Furthermore, the client code continues to work on objects supporting an expanded interface.

An interface may contain other interfaces and add new operations. An object whose type is given by the expanded interface supports the union of the operations of the contained interfaces and the new operations. An object supporting the expanded interface may be accessed by code expecting an object supporting one of the contained interfaces. If an interface is defined by combining multiple interfaces, an interface lattice results.

Similarly, an implementation may be provided in terms of other existing implementations.

That is, rather than providing implementations for all of the operations of an interface, an implementation may inherit some code and representation from other implementations. In the presence of multiple inheritance of implementations, an implementation lattice results.

Software reusability:-

When behavior is inherited from another class, the code that provides that behavior does not have to be rewritten. This may seem obvious, but the implementations are important. Many programmers spend much of their time rewriting code, they have written many times before- for example, to search for a pattern in a string or to insert a new element into a table. With object oriented techniques, these functions can be written once reused.

Other benefits of reusable code include increased reliability and the decreased maintenance cost because of sharing by all users of the code.

CRC CARD

A CRC Card is an index card that is use to represent the responsibilities of classes and the interaction between the lasses. CRC cards are an informal approach to object oriented modeling. The cards are created through scenarios, based on the system requirement that model the requirement of the system.

CRC(class responsibility- collaborator) card modeling is a simple but yet powerful object oriented analysis technique. Crc modeling often includes the user analysts, and developers in a modeling and design process, bringing together the entire development team to form a common understanding of an object oriented development project. It is one of many tools that should be used in the collaborative design of a system.

Why uses CRC cards?

They are portable, no computers are required so that they can be used anywhere, even away from the office.

They allow the participants to experience first hand how the system will work. No computer toll can replace the interaction that happens physically picking up the cards and playing the role of that object.

They are essential tool for teaching people the object oriented paradigm.

They can be used as a methodology themselves or as a front end to a more formal methodology.

CRC card are created for teaching, they are proven useful for much more. They became an expected method for analysis and design. The biggest contribution factor the their success is the fact is that they provide an informal and non threatening environment that is productive to working and learning.

Components of crc card

A crc model is a collection of cards that are divided into three sections.

Class

Responsibility

Collaborator

 

Class

Component

collaborator

Responsibility

 
 

The back of the crc card is often used for a model detailed description of the class along with any other notes captured during the CRC session. Much time these include the actual attributes of the class.

  • Class:- a class represents a collection of similar objects. Objects are things of

interest in the system being modeled. They can be a person, place, thing, or any

other concept important to the system at hand. The class name appears across the top of the crc card.

Responsibility:- responsibility is anything that the class knows or does. These responsibility are things that the class has knowledge about itself, or things the class can do with the knowledge it has. For example, a person class might have knowledge for its name, address and phone number. In another example an automobile class might have knowledge of its size, its number of doors, or it might be able to do things like stop and go. The responsibilities of a class appear along the left side of the crc card.

  • Collaborator:- a collaborator is another class, that is used to get information for,

or performs action for the class at the hand. It often works with the particular class

to complete a step in a scenario. The collaborator of a class appears along the right side of the crc card.

IS A RULE VS HAS A RULE

One of the advantages of object oriented programming language is code reuse. There are two ways we can do code reuse either by implementation of inheritance(is a relationship) or object composition (has a relationship). Although the compiler and java virtual machine will do a lot of work for you when you use inheritance, you can also get at the functionality of inheritance when you use composition.

IS A RELATIONSHIP:-

In object oriented programming, the concept of IS-A is a totally based on inheritance, which can be of two types class inheritance or interface inheritance.

It is just like saying “ A is a B if A is a specialization of B. this means that every instance of type A can do at least the things that B can do, i.e it shows the same behavior for the same message. for example , Apple is a fruit, car is a vehicle etc. inheritance is unidirectional. For example house is a building. But building is not a house.

example:

Class b { }; Class a:public b {

}

It is key point to note that you can easily identify the IS-A relationship. Wherever you seen an extends keyword or implements keyword in a class declaration, then this class is said to have IS-A relationship.

HAS-A relationship:-

Composition(HAS-A) simply mean use of instance variables that are references to other objects. As the name suggests A has a member variable of type B. A is not a specialization of B and thus does not inherit anything from B. the corresponding example:

Class B

{

};

Class A{

B b;

};

As you can see class A does not have to show the same behaviour as B. this means that A does not have to respond to the same messages as B. i.e A does not have to have the same methods as B. they can be completely different or partially overlapping.

Lets understand these concepts with example or car class.

Comparing composition and inheritance:  It is easier to change the class implementing composition than inheritance.

Comparing composition and inheritance:

It is easier to change the class implementing composition than inheritance. The change of a superclass impacts the inheritance hierarchy to subclasses. You can’t add to a subclass a method with the same signature but a different return type as a method inherited from a superclass. Composition, on the other hand, allows you to change the interface of a front end class without affecting back end classes. Composition is dynamic binding while inheritance is static binding It is easier to add new subclasses than it is to add new front end classes , because inheritance comes with polymorphism. If you have a bit of code that relies only on a superclass interface, that code can work with a new subclass without change. This is not true of composition , unless you use composition with interface. Used together, composition and interface make a very powerful design tool.