01chapter One - Introduction To OOP
01chapter One - Introduction To OOP
Users concentrate on defining input and output rather than the program steps
required
Declarative programming examples are CSS, HTML, XML, SQL, Prolog etc.
E.g.: HTML describes what should appear on a web page, not how it should be
drawn on the screen.
The execution of the program is very much like proof of mathematical statement, e.g., Prolog
Function can be replaced with their values without changing the meaning of the program. E.g
perl, javascript mostly uses this paradigm.
Program statements are defined by data rather than hard-coding a series of steps.
Eg. SQL
WHY YOU SHOULD USE DECLARATIVE
PROGRAMMING?
Reusability-
Not rewriting code can speed up the program you are currently
writing and any others that use the same functionality in the future.
Reducing Errors:
the chances of errors arising are smaller and it allows for your
application to become more stable.
POTENTIAL DRAWBACKS OF
DECLARATIVE PROGRAMMING
Lack of Control:
In declarative programming, you may use functions that someone else created,
in order to achieve the desired results.
But you may need specific things to be completed behind the scenes to make
your result come out properly.
Inefficiency:
When the implementation is controlled by something else, you may have problems
In applications where there may be a time constraint, you will need to program the
individual steps in order to make sure your program is running as efficient as possible.
ii. Imperative programming paradigm
A programming language that requires programming discipline such as C/C++,
Java, COBOL, FORTRAN, Perl and JavaScript.
x=x+1; - how
This is the form and style of programming in which we care about how we get to
an answer, step by step.
We want the same result ultimately, but we are telling the complier to do things a
certain way in order to achieve that correct answer we are looking for.
EXAMPLE
To give directions in an imperative fashion, you say, “Go to 1st Street, turn left
onto Main, drive two blocks, turn right onto Maple, and stop at the third
house on the left.” The declarative version might sound something like this:
“Drive to Sue’s house.” One says how to do something; the other says what
needs to be done.
a) Procedural programming,
An OOP uses a set of objects, which will communicate by sending and
receiving messages to request services or information.
• Logically, you would expect a person to have a name. This would be considered a property of the person.
• You would also expect a person to be able to do something, such as walking. This would be considered a
method of the person.
Object can move and communicate with Data cannot be moved liberally from
each other through member functions function to function
Function Function
FUNC FUNCTI FUNCTION
TION 1 ON 2 3
Object 3
Data
FUNCTION FUNCTION
Function 4 5
OVERVIEW OF OOP CONCEPTS
They are:
Encapsulation,
Inheritance, and
Polymorphism.
ENCAPSULATION
Encapsulation: Hiding implementation details of an object from its
clients.
In inheritance,
the derived class is called class or the subclass or we can say the extend
class
The class from which we are deriving the subclass is called the base class
or the parent class
By use of inheritance, an object need only define those qualities that
make it unique within its class.
Question? ?