Geeks Talk

Prepare for your Next Interview




Oops

This is a discussion on Oops within the OOPS forums, part of the Software Development category; Can anybody explain OOPS th examples. Thank lot dmdevaraj...

  #1 (permalink)  
Old 10-08-2008
Junior Member
 
Join Date: Apr 2008
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
dmdevaraj is on a distinguished road
Oops

Can anybody explain OOPS th examples.

Thank lot

dmdevaraj
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-13-2008
Junior Member
 
Join Date: Oct 2008
Location: chennai
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
ba_vani is on a distinguished road
Re: Oops

A large application consists of component objects, which interact with each other. These components can be used to develop various applications. This is referrd to as the object-oriented approach to develop an application.

For example, ServeYourMoney bank needs to calculate the salaries of its employees. The salary is calculated on the basis of the base slary of an employee, number of leaves taken by the employee in excess to the leaves allowed in a month, and dearness and housing allowance. The organization consists of various types of employees, such as regular, contract, and waged.

Smith is a programmer, develops a code to calculate the employees' salaries by using an object-oriented programming langugage. This code is reused for employees at all levels. Reusability of code enables Smith to use the same code for employees at all levels.
Reply With Quote
  #3 (permalink)  
Old 10-13-2008
Junior Member
 
Join Date: Oct 2008
Location: chennai
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
ba_vani is on a distinguished road
Thumbs up Re: Oops

Quote:
Originally Posted by ba_vani View Post
A large application consists of component objects, which interact with each other. These components can be used to develop various applications. This is referrd to as the object-oriented approach to develop an application.

For example, ServeYourMoney bank needs to calculate the salaries of its employees. The salary is calculated on the basis of the base slary of an employee, number of leaves taken by the employee in excess to the leaves allowed in a month, and dearness and housing allowance. The organization consists of various types of employees, such as regular, contract, and waged.

Smith is a programmer, develops a code to calculate the employees' salaries by using an object-oriented programming langugage. This code is reused for employees at all levels. Reusability of code enables Smith to use the same code for employees at all levels.
All the best
Reply With Quote
The Following User Says Thank You to ba_vani For This Useful Post:
  #4 (permalink)  
Old 10-16-2008
Contributing Member
 
Join Date: Oct 2008
Location: tamilnadu,india
Posts: 74
Thanks: 2
Thanked 5 Times in 5 Posts
rakesh trichy is on a distinguished road
Re: Oops

An object-oriented programming language (also called an OO language) is one that allows or encourages, to some degree, object-oriented programming techniques such as encapsulation, inheritance, modularity, and polymorphism.

Organize a program around its data (object)& set well define interface to that data. i.e. objects and a set of well defined interfaces to that data
Reply With Quote
The Following User Says Thank You to rakesh trichy For This Useful Post:
  #5 (permalink)  
Old 4 Weeks Ago
Junior Member
 
Join Date: Apr 2008
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
dmdevaraj is on a distinguished road
Re: Oops

Hi ba_vani,
The code reusable is avaliable in all languages (like procedures and functions). Then why is it called as OOPS?

Last edited by dmdevaraj : 4 Weeks Ago at 04:11 AM.
Reply With Quote
  #6 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: May 2008
Location: Delhi
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
shivamrastogi is on a distinguished road
Re: Oops

The Example of OOPS are Encapculation,abstraction,Inharitance,Polymorphism.
Reply With Quote
  #7 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: May 2008
Location: Delhi
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
shivamrastogi is on a distinguished road
Re: Oops

This is true that all the languages the facility of re-usable code but for OOPS it uis necessary that the code will follow the following property like encapsulation, inheritance, modularity, and polymorphism.
Reply With Quote
The Following User Says Thank You to shivamrastogi For This Useful Post:
  #8 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: Apr 2008
Posts: 9
Thanks: 5
Thanked 0 Times in 0 Posts
dmdevaraj is on a distinguished road
Re: Oops

what are these >>encapsulation, inheritance, modularity, and polymorphism? can u explain with examples.
Reply With Quote
  #9 (permalink)  
Old 2 Weeks Ago
Contributing Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 85
Thanks: 0
Thanked 8 Times in 8 Posts
amitpatel66 is on a distinguished road
Re: Oops

There are three major features in object-oriented programming: encapsulation, inheritance and polymorphism.

Encapsulation Enforces Modularity

Encapsulation refers to the creation of self-contained modules that bind processing functions to the data. These user-defined data types are called "classes," and one instance of a class is an "object." For example, in a payroll system, a class could be Manager, and Pat and Jan could be two instances (two objects) of the Manager class. Encapsulation ensures good code modularity, which keeps routines separate and less prone to conflict with each other.

Inheritance Passes "Knowledge" Down

Classes are created in hierarchies, and inheritance allows the structure and methods in one class to be passed down the hierarchy. That means less programming is required when adding functions to complex systems. If a step is added at the bottom of a hierarchy, then only the processing and data associated with that unique step needs to be added. Everything else about that step is inherited. The ability to reuse existing objects is considered a major advantage of object technology.

Polymorphism Takes any Shape

Object-oriented programming allows procedures about objects to be created whose exact type is not known until runtime. For example, a screen cursor may change its shape from an arrow to a line depending on the program mode. The routine to move the cursor on screen in response to mouse movement would be written for "cursor," and polymorphism allows that cursor to take on whatever shape is required at runtime. It also allows new shapes to be easily integrated.
Reply With Quote
  #10 (permalink)  
Old 2 Weeks Ago
Contributing Member
 
Join Date: Nov 2008
Location: Chennai
Posts: 85
Thanks: 0
Thanked 8 Times in 8 Posts
amitpatel66 is on a distinguished road
Re: Oops

Fundamental Concepts of OOPS

Class

Defines the abstract characteristics of a thing (object), including the thing's characteristics (its attributes, fields or properties) and the thing's behaviors (the things it can do, or methods, operations or features). One might say that a class is a blueprint or factory that describes the nature of something. For example, the class Dog would consist of traits shared by all dogs, such as breed and fur color (characteristics), and the ability to bark and sit (behaviors). 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 (generally using encapsulation). Collectively, the properties and methods defined by a class are called members.

Object

A pattern (exemplar) of a class. The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has brown-and-white fur.

Instance

One can have an instance of a class or a particular object. The instance is the actual object created at runtime. In programmer jargon, the Lassie object is an instance of the Dog class. The set of values of the attributes of a particular object is called its state. The object consists of state and the behaviour that's defined in the object's class.

Method

An object's abilities. In language, methods are verbs. Lassie, being a Dog, has the ability to bark. So bark() is one of Lassie's methods. She may have other methods as well, for example sit() or eat() or walk() or save_timmy(). Within the program, using a method usually affects only one particular object; all Dogs can bark, but you need only one particular dog to do the barking.

Message passing

“The process by which an object sends data to another object or asks the other object to invoke a method.” Also known to some programming languages as interfacing. E.g. the object called Breeder may tell the Lassie object to sit by passing a 'sit' message which invokes Lassie's 'sit' method. The syntax varies between languages, for example: [Lassie sit] in Objective-C. In Java code-level message passing corresponds to "method calling". Some dynamic languages use double-dispatch or multi-dispatch to find and pass messages.

Inheritance

‘Subclasses’ are more specialized versions of a class, which inherit attributes and behaviors from their parent classes, and can introduce their own.
For example, the class Dog might have sub-classes called Collie, Chihuahua, and GoldenRetriever. In this case, Lassie would be an instance of the Collie subclass. Suppose the Dog class defines a method called bark() and a property called furColor. Each of its sub-classes (Collie, Chihuahua, and GoldenRetriever) will inherit these members, meaning that the programmer only needs to write the code for them once.
Each subclass can alter its inherited traits. For example, the Collie class might specify that the default furColor for a collie is brown-and-white. The Chihuahua subclass might specify that the bark() method produces a high pitch by default. Subclasses can also add new members. The Chihuahua subclass could add a method called tremble(). So an individual chihuahua instance would use a high-pitched bark() from the Chihuahua subclass, which in turn inherited the usual bark() from Dog. The chihuahua object would also have the tremble() method, but Lassie would not, because she is a Collie, not a Chihuahua. In fact, inheritance is an ‘is-a’ relationship: Lassie is a Collie. A Collie is a Dog. Thus, Lassie inherits the methods of both Collies and Dogs.

Multiple inheritance is inheritance from more than one ancestor class, neither of these ancestors being an ancestor of the other. For example, independent classes could define Dogs and Cats, and a Chimera object could be created from these two which inherits all the (multiple) behavior of cats and dogs. This is not always supported, as it can be hard both to implement and to use well.

Abstraction

Abstraction is simplifying complex reality by modelling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.
For example, Lassie the Dog may be treated as a Dog much of the time, a Collie when necessary to access Collie-specific attributes or behaviors, and as an Animal (perhaps the parent class of Dog) when counting Timmy's pets.

Abstraction is also achieved through Composition. For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more components. To build the Car class, one does not need to know how the different components work internally, but only how to interface with them, i.e., send messages to them, receive messages from them, and perhaps make the different objects composing the class interact with each other.

Encapsulation

Encapsulation conceals the functional details of a class from objects that send messages to it.
For example, the Dog class has a bark() method. The code for the bark() method defines exactly how a bark happens (e.g., by inhale() and then exhale(), at a particular pitch and volume). Timmy, Lassie's friend, however, does not need to know exactly how she barks. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class. The reason for encapsulation is to prevent clients of an interface from depending on those parts of the implementation that are likely to change in future, thereby allowing those changes to be made more easily, that is, without changes to clients. For example, an interface can ensure that puppies can only be added to an object of the class Dog by code in that class. Members are often specified as public, protected or private, determining whether they are available to all classes, sub-classes or only the defining class. Some languages go further: Java uses the default access modifier to restrict access also to classes in the same package, C# and VB.NET reserve some members to classes in the same assembly using keywords internal (C#) or Friend (VB.NET), and Eiffel and C++ allow one to specify which classes may access any member.

Polymorphism

Polymorphism allows the programmer to treat derived class members just like their parent class' members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior. One method, or an operator such as +, -, or *, can be abstractly applied in many different situations. If a Dog is commanded to speak(), this may elicit a bark(). However, if a Pig is commanded to speak(), this may elicit an oink(). They both inherit speak() from Animal, but their derived class methods override the methods of the parent class; this is Overriding Polymorphism. Overloading Polymorphism is the use of one method signature, or one operator such as ‘+’, to perform several different functions depending on the implementation. The ‘+’ operator, for example, may be used to perform integer addition, float addition, list concatenation, or string concatenation. Any two subclasses of Number, such as Integer and Double, are expected to add together properly in an OOP language. The language must therefore overload the concatenation operator, ‘+’, to work this way. This helps improve code readability. How this is implemented varies from language to language, but most OOP languages support at least some level of overloading polymorphism. Many OOP languages also support Parametric Polymorphism, where code is written without mention of any specific type and thus can be used transparently with any number of new types. Pointers are an example of a simple polymorphic routine that can be used with many different types of objects.

Decoupling

Decoupling allows for the separation of object interactions from classes and inheritance into distinct layers of abstraction. A common use of decoupling is to polymorphically decouple the encapsulation, which is the practice of using reusable code to prevent discrete code modules from interacting with each other.

Not all of the above concepts are to be found in all object-oriented programming languages, and so object-oriented programming that uses classes is called sometimes class-based programming. In particular, prototype-based programming does not typically use classes. As a result, a significantly different yet analogous terminology is used to define the concepts of object and instance.
Reply With Quote
The Following User Says Thank You to amitpatel66 For This Useful Post:
  #11 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: May 2008
Location: india
Posts: 10
Thanks: 1
Thanked 1 Time in 1 Post
anveth is on a distinguished road
Re: Oops

Inheritance means acquiring the properties from an existing one.
for example if we take a class Animal that contains two methods i.e bark() and food().
Then its sub classes (dog or tiger) can aquire that methods by using 'extend' keyword as shown below
class Animal
{
void bark()
{
System.out.println("bark sound");
}
void food(){
System.out.println("meat");
}
}
class Dog extends Animal
{

void petdog()
{
System.out.println("pet dog");
}
}
class Demo
{
public static void main(String args[])
{
Dog d=new Dog();
d.bark();
d.food();
d.petdog();
}
}
//o/p:bark sound
meat
pet dog
//by using inheritance we can use two methods in sub class

Last edited by anveth : 2 Weeks Ago at 01:19 AM. Reason: little bit corections
Reply With Quote
  #12 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: May 2008
Location: india
Posts: 10
Thanks: 1
Thanked 1 Time in 1 Post
anveth is on a distinguished road
Re: Oops

I know that
Abstraction means hiding details i.e data and methods from outside the program that needs to be protected.
Encapulation means binding or wraping data and methods.


but i had an confusion that this two concepts are same, but differ in definition.

please some body clear my doubt that really this two concepts are same.
Reply With Quote
The Following User Says Thank You to anveth For This Useful Post:
Reply

  Geeks Talk > Software Development > OOPS


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
oops amaravadi.krishna81 OOPS 9 10-26-2008 02:18 AM
oops abuhurera farooqe OOPS 3 10-16-2008 10:02 AM
what are the disadvatages of oops? ramakris143 OOPS 1 10-29-2007 03:14 PM
what are the disadvatages of oops? ramakris143 Java 4 10-10-2007 04:51 AM
OOPs........ Sampath_Java Java 2 09-12-2007 09:45 AM


All times are GMT -4. The time now is 02:17 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved