This document compares procedural programming and object-oriented programming approaches to a shape rotation and sound playback problem. It shows how the OO approach using classes and inheritance can better handle changes to requirements by separating common behavior into a base class and allowing derived classes to override specific behaviors as needed. This reduces duplicated code and makes the solution more flexible and maintainable.
This slide notes are more than 10 years old of my teacher Mr Karim Zebari. He uses a brilliant simple language to explain programming principles step by step.
This document discusses the differences between procedural and object-oriented programming. Procedural programming focuses on functions while object-oriented programming focuses on classes and the methods within them. Object-oriented programming combines data and operations, whereas procedural programming separates them. A class defines the variables and methods that objects of that class will have. An object is an instance of a class, and has the data and behaviors defined by its class. A class can contain fields to store data, methods to manipulate the data, and nested classes and interfaces. An example Pencil class is provided with fields to store attributes and a method to set the color.
Here are the key concepts of Object Oriented Programming:
- Object: An object represents a real world entity with attributes and behaviors. Ex: Person, Bank Account etc.
- Class: A class defines the common attributes and behaviors of objects. It acts as a blueprint to create objects.
- Encapsulation: Wrapping up of data and methods into a single unit called class. It hides internal details and represents as a single unit.
- Inheritance: Ability to create new classes from existing classes by extending their features. New classes inherit attributes and behaviors of parent classes.
- Polymorphism: Ability of an object to take multiple forms. Same method can act differently depending on the object that inv
C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX
Most C++ compilers don't care what extension you give your source code, but if you don't specify otherwise, many will use .cpp by default
Most frequently used and free available compiler is GNU C/C++ compiler, otherwise you can have compilers either from HP or Solaris if you have respective Operating Systems.
The document discusses the history and evolution of programming languages from the 1940s to present. It notes that early languages provided little abstraction from computer hardware, but that over time languages increasingly abstracted complexity and improved developer productivity. The document outlines the development of assembly languages, third generation languages like FORTRAN, and more modern paradigms like object-oriented programming. It also discusses influential ideas like structured programming and the "GOTO controversy" that aimed to improve programming practices.
Manufacturing process of yogurt and dahiNajja Tariq
This document provides information about the manufacturing processes of yogurt and dahi. Yogurt is made by fermenting milk with Lactobacillus bulgaricus and Streptococcus thermophilus cultures, giving it a tart flavor. Dahi is similarly made by fermenting milk or cream but uses different starter cultures. Both products are high in protein and beneficial bacteria. The processing involves steps like standardizing, pasteurizing, homogenizing, cooling, inoculating with cultures, incubating, and packaging the fermented milk.
Scala is a programming language that runs on the JVM and fuses functional and object-oriented paradigms. It aims to provide functional programming for programmers with an imperative mindset. Key features include functions as first-class values, pattern matching, traits for composition, and seamless interoperability with Java. While some features appear to be language features, many are actually implemented via libraries. The Scala community is growing with adoption by companies and increasing support in tools and publications.
The objectives of the seminar are to shed a light on the premises of FP and give you a basic understanding of the pillars of FP so that you would feel enlightened at the end of the session. When you walk away from the seminar you should feel an inner light about the new way of programming and an urge & motivation to code like you never before did!
Functional programming should not be confused with imperative (or procedural) programming. Neither it is like object oriented programming. It is something different. Not radically so, since the concepts that we will be exploring are familiar programming concepts, just expressed in a different way. The philosophy behind how these concepts are applied to solving problems are also a little different. We shall learn and talk about essentially the fundamental elements of Functional Programming.
This document provides an overview of object-oriented programming concepts such as objects, classes, and messaging. It defines an object as having state represented by variables and behavior represented by methods. A class is described as a blueprint that defines common attributes and behaviors of objects. The document also explains how objects communicate by sending messages to each other to invoke methods.
Basic concepts of object oriented programmingSachin Sharma
This document provides an overview of basic concepts in object-oriented programming including objects, classes, data abstraction, encapsulation, inheritance, polymorphism, binding, and message passing. Objects are run-time entities with state and behavior, while classes define the data and behavior for objects of a similar type. Encapsulation binds data and functions within a class, while inheritance allows new classes to acquire properties of existing classes. Polymorphism enables one function to perform different tasks. Binding determines how function calls are linked, and message passing allows objects to communicate by sending requests.
Introduction to Object Oriented ProgrammingMoutaz Haddara
An Introduction to Object-Oriented Programming (OOP)
Download the presentation to view it correctly, as it has some animations that won't show here.
If you have any questions, please contact me. You are free to use it this presentation, but it would be nice at least to give me some credit :)
Content:
1- History of Programming
2. Objects and Classes
3- Abstraction, Inheritance, Encapsulation, and Polymorphism
(video of these slides available here http://fsharpforfunandprofit.com/fppatterns/)
In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID.
The functional programming community has design patterns and principles as well.
This talk will provide an overview of some of these, and present some demonstrations of FP design in practice.
2. Requirement Spec
• There will be a shape on a GUI, a square, a
circle and a triangle
• When the user clicks on the shape, the shape
will rotate clockwise 360 degrees and play a
.wav sound file specific to that shape
1 2
3
3. Step 1
Procedural programming OO programming
rotate(shapeNum) Square
{
rotate()
//make the shape rotate 360 degrees Circle
{
} //code to rotate a square
rotate()
} Triangle
{
playsound(shapeNum) //code to rotate a circle
playsound() rotate()
{ {
}
{
//use shapeNum to lookup which //code to play the .wav //code to rotate a triangle
playsound()
//WAV sound file to play and play it // file for the square }
{
}
} //code to play the .wav
playsound()
// file for the circle
{
}
//code to play the .wav
// file for the triangle
}
4. Change in Spec
• A new shape is added – amoeba shape along
with the others
• When the user clicks on the amoeba, the
shape will rotate clockwise 360 degrees and
play a .mp3 sound file and not a .wav file
1 4
2
3
5. Step 2
Procedural programming OO programming
rotate(shapeNum) Square
{rotate(shapeNum)
{//make the shape rotate 360 degrees rotate()Circle
} //make the shape rotate 360 degrees {
//code to rotate a square
rotate() Triangle
} } {
playsound(shapeNum) //code to rotateAmoeba
rotate() a circle
{playsound(shapeNum) playsound()
} {
{ //coderotate() a triangle
to rotate
{ //if the shape is not an amoeba use //code to play the .wav {
playsound() }
//shapeNum to look lookup which
//use shapeNum to up which .wav // file {for the square //code to rotate the amoeba
// file to play it to play and play it
//WAV sound file } }
//code to play the .wav
playsound()
// else
} // file for the circle
{
//play amoeba .mp3 file } //code playsound().wav
to play the
{ the triangle
// file for
} } //code to play the .mp3
// file for the amoeba
}
rotate() will still work but the playsound()
will need to be changed
6. Issue with Implementation
• The logic for the rotate function was
implemented as:
– Determine the rectangle that surrounds the shape
– Calculate the center of the rectangle and rotate
the shape around that point
7. Actual logic that client wanted
• For the amoeba shape the client wanted the
rotate to be implemented differently
• The amoeba shape was suppose to rotate
around a point at one end
implemented required
8. Step 3
Procedural programming OO programming
rotate(shapeNum, xpt,ypt) Square
{
//If the shape is not amoeba rotate()Circle
//calc the center point {
//code to rotate a square
rotate() Triangle
//based on the rectangle } {
//then rotate //code to rotateAmoeba
rotate() a circle
//else playsound()
} {
{ //codeint xpt,ypt; triangle
to rotate a
//use the xpt and ypt as the //code to play the .wav rotate()
playsound() }
//rotation point offset // file {for the square {
//and then rotate } //code to play the .wav to rotate the amoeba
playsound() //code
} // file for the circle//using amoeba’s x and y
{
} //code }to play the .wav
// file for the triangle
} playsound()
{
•Lot of code affected //code to play the .mp3
•Previously tested code changed // file for the amoeba
•What if the specification changed again }
9. Step 4 – Common behavior
OO programming
Square Amoeba
rotate() int xpt,ypt;
{ rotate()
Circle
//code to rotate a {
square //code to rotate the
rotate()
} amoeba
{ Triangle //using amoeba’s x and y
//code to rotate a circle
playsound() }
} rotate()
{ {
//code to play the .wav playsound()
playsound() //code to rotate a triangle
// file for the square {
{ }
} //code to play the .mp3
//code to play the .wav
// file for the amoeba
// file for the circle
playsound() }
} {
//code to play the .wav
// file for the triangle
} What the classes have in common?
10. Step 5 – Base class design
OO programming
Shape
rotate()
{
//common features
}
playsound()
{
//common features
}
Design the base class
11. Step 6 – Relationship
OO programming
Shape
rotate()
playsound()
Amoeba Triangle Square Rectangle
Inheritance : Base and derived class relationship
12. Step 6 – Overriding
OO programming
Shape
rotate()
playsound()
Amoeba Triangle Square Rectangle
rotate() {
//amoeba specific
//rotate code }
playSound() { Overriding: Derived class redefines one of its inherited methods
//amoeba specific
//sound code}
When it needs to change or extend the behavior of that method