Agents and Communities
Agents and Communities
Agents and Communities
Programming through
JAVA
Dr. K. Kavitha
Learning Objectives
State what is meant by “Object Oriented
Programming”.
Discuss the Object Oriented Problem solving
paradigm as a way of viewing the world.
State and explain the key terms of object
orientation, such as ,
Classes & Instances
Methods & Messages
Encapsulation & Information hiding
Inheritance
Computer Programming
The history of computer
programming is a steady move
away from machine-oriented
views of programming towards
concepts and metaphors that
more closely reflect the way in
which we ourselves understand
the world
3
Programming progression…
4
Machine language – Mark I
5
Machine Language
6
Assembly Language – PDP-11
7
Assembly Language – Macro-11
GCD: TST B
BEQ SIMPLE
MOV A, R5
SXT R4
DIV B, R4
MOV B, A
MOV R5, B
CALL GCD
SIMPLE: RETURN
8
Assembly Language – Macro-11
GCD: TST B
BEQ SIMPLE
MOV A, R5
SXT R4
DIV B, R4
MOV B, A
MOV R5, B
CALL GCD
SIMPLE: RETURN
9
Machine-Independent Programming Languages
– Fortran ! This example program solves for roots of the quadratic equation,
! ax^2 +bx +c =0,for given values of a, b and c.
!
PROGRAM bisection
IMPLICIT NONE
INTEGER :: iteration
DOUBLE PRECISION :: CC, Er, xl, x0, x0_old, xr
! Bisection method.
Er =CC +1
iteration = 0
DO WHILE (Er > CC)
iteration = iteration + 1
10
Procedures & Functions – Pascal
program ValueArg(output);
{Shows how to arrange for a procedure to have arguments.}
begin
PrintInitials (‘D’, ‘C’); {Any two characters can be arguments.}
PrintInitials (‘Q’, ‘T’); {Like strings, characters are quoted.}
PrintInitials (‘&’, ‘#’)
end. {ValueArg}
11
Objects
(This example is from Java)
class Time {
13
Why is Object Oriented
Programming a Paradigm?
The approach to
problem solving
16
Agents and Communities
17
Agents and Communities
An object oriented program is structured as a
community of interacting agents, called
objects.
Each object has a role to play.
Each object provides a service, or performs
an action, that is used by other members of
the community.
Agents and Communities
Agents and Communities
What is an object?
21
What is Object Oriented
Programming?
Identifying objects and
assigning responsibilities to
these objects.
Objects communicate to
An object is like a
other objects by sending
black box.
messages.
The internal
Messages are received by
details are
the methods of an object
hidden.
22
So, what are objects?
23
Why do we care about objects?
24
Example: The Person class
#include<string>
#include<iostream>
class Person{
char name[20]; private
int yearOfBirth; data
public:
void displayDetails() {
system.out.print(name + " born in "
+ yearOfBirth );
} public
//... processes
};
The two parts of an object
= +
26
Basic Terminology
27
Basic Terminology:
Inheritance
Inheritance means that one class inherits the
characteristics of another class.
This is also called a “is a” relationship:
A car is a vehicle
A dog is an animal
A teacher is a person
28
Basic Terminology:
Polymorphism
Polymorphism means “having many forms”. It
allows different objects to respond to the
same message in different ways, the
response specific to the type of the object.
29
Basic Terminology:
Aggregation
Aggregation describes a “has a” relationship.
One object is a part of another object.
A car has wheels.
30
Basic Terminology:
Behaviour and Messages
The most important aspect of an object is its
behaviour (the things it can do). A behaviour
is initiated by sending a message to the
object (usually by calling a method).
31
Messages and Methods
The chain reaction that ultimately resulted in
the solution to Chris's problem began with a
request given to the florist.
This request lead to other requests, which
lead to still more requests, until the flowers
ultimately reached Chris's friend Robin.
We see, therefore, that members of this
community interact with each other by making
requests. So, our next principle of object-
oriented problem solving is the vehicle used
to indicate an action to be performed.
Messages and Methods
Action is initiated in object-oriented programming by
the transmission of a message to an agent (an
object) responsible for the action.
The message encodes the request for an action and
is accompanied by any additional information
(arguments) needed to carry out the request.
The receiver is the object to whom the message is
sent. If the receiver accepts the message, it accepts
the responsibility to carry out the indicated action.
In response to a message, the receiver will perform
some method to satisfy the request.
Messages and Methods
51
Object Oriented approach as a method to
promote reusability of software
Features of JAVA
55
Conclusions
Object-oriented programming provides a superior
way of organizing programming projects
It encourages a high degree of modularity in
programming, making large projects easier to
implement
It provides powerful techniques like inheritance and
polymorphism to help organize and reuse code
Object-oriented languages like Java both provide
a good environment for beginning students to
learn programming, and match real-world
developments in computer programming
56