Beruflich Dokumente
Kultur Dokumente
programming
programming paradigm based on the
concept of objects
Features
The main idea of object-oriented
programming is that everything is an
object. However, the object can be of
different types:
Examples
In the examples below, we create a class
called Human . This class contains the
attributes name (for the name of the
person) and friend (for the name of
the friend). Each of the methods in the
Human class contains a list of
instructions that makes use of both the
name and friend attributes.
Python …
class Human
Human(object):
def __init__(self,
name, friend=None):
self.name = name
self.friend =
friend
def say_name(self):
print("My name is
print
"+self.name)
def
say_goodnight(self):
if self.friend is
None:
print("Good
print
night nobody.")
else:
else
print("Good
print
night "+self.friend.name)
stephen.say_name() # Shows
'My name is Stephen'
stephen.say_goodnight() #
Shows 'Good night nobody.'
joe.say_name() # Shows 'My
name is Joe'
joe.say_goodnight() # Shows
'Good night Stephen'
Java …
This code is in Java.
class Human {
private String name =
"unnamed"; // the name of
this Human
private Human friend =
null; // the Human's friend
null
System.out.println("My name
is " + this
this.name);
}
public void
sayGoodnight() {
if (friend == null
null)
{
System.out.println("Good
night nobody.");
} else {
System.out.println("Good
night " + friend.name);
}
}
}
// Create a new
Human object joe with name
"Joe" and stephen as a
friend
Human joe = new
Human("Joe", stephen);
stephen.sayName();
// Shows 'My name is
Stephen'
stephen.sayGoodnight(); //
Shows 'Good night nobody.'
joe.sayName(); //
Shows 'My name is Joe'
joe.sayGoodnight();
// Shows 'Good night
Stephen'
}
}
Criticism
Even though object-oriented programming
is popular, but there are many people who
think that it is bad and criticize it.
References
1. "Mode inheritance, cloning, hooks &
OOP (Google Groups Discussion)" .
2. http://www.csm.ornl.gov/~v8q/Home
page/Papers%20Old/spetep-
%20printable.pdf
3. C. J. Date, Introduction to Database
Systems, 6th-ed., Page 650
4. "The AI Effect" .
5. "STLport: An Interview with A.
Stepanov" . www.stlport.org.
Retrieved from
"https://simple.wikipedia.org/w/index.php?
title=Object-
oriented_programming&oldid=6714309"