SlideShare a Scribd company logo
1 of 43
Introduction to
Object-Oriented
Programming
Problem Solving
 The key to designing a solution is breaking it
down into manageable pieces
 When writing software, we design separate
pieces that are responsible for certain parts of
the solution
 Two popular programming design
methods:
 Structured Programming (SP)
 Object-Oriented Programming (OOP)
Problem Solving
SP
 Procedural based approach
 Main problem will be divided into sub-
problems
 Analyze and refine each sub-problem
 All sub-problem solutions are implemented as
procedures and combined to solves the main
problem
Object-Oriented
Programming
 Object based approach
 objects as foundation for problem solving
 Identify objects from the main problem
 An OOP program is a collection of objects
that interacts each other
Object-Oriented
Programming
 More natural way to solve problem
 Objects can be used to represent real-world
entities
 For instance, an object might represent a
particular employee in a company
 Each employee object handles the
processing and data management related to
that employee
Objects
 Object-oriented programs use objects, which
represent real world objects.
 A real world object is a thing, both tangible and
intangible.
 An object has:
 state (it has various properties, which might change)
 behaviour (it can do things and can have things done
to it)
7
Objects
 OOProgramming software objects
 Software objects have state
 Instance Variable/Data/Field
 Software objects have behaviour
 Method
8
Object’s
members
Objects interactions
 OOP also involves interactions between
objects through calling (invoking) of
methods.
9
Method CallsThe OilSensor object calls the warning() method
of the Controller, which then invokes the OilLight
TurnOn() method.
Method can Return Values
 Return value: A result that the method has
computed and returns it to the caller
 Can returns 0 or 1 value
Scanner s = new Scanner(System.in);
int num = s.nextInt();
10
Continued…
Classes and Objects
 To create an object , we MUST provide a
definition/description for it
 A class is a description/blue print of a kind of
object
 It does not by itself create any objects
How to create an object ?
 An object is called an instance of a class
Object instantiation – process of creating an object
11
Example of Java class:
The String Class
12
Creating Objects
 A variable holds either a primitive type or a
reference to an object
 A class name can be used as a type to declare an
object reference variable
String name;
 No object is created with this declaration
 An object reference variable holds the address of
an object
 The object itself must be created separately
13
Creating Objects
 Generally, we use the new operator to create
an object
14
name = new String (“Ali bin Ahmad");
This calls the String constructor, which is
a special method that sets up the object
• Creating an object is called instantiation
• An object is an instance of a particular class
Constructing String
objects
Strings stringRef = new String(stringLiteral);
eg.
String name = new String(“Muhammad Haziq”);
Since strings are used frequently, Java provides a
shorthand notation for creating a string:
String name = "Muhammad Haziq”;
15
Constructing String objects
 New String objects are created whenever the
String constructors are used:
16
String name4 = new String(); // Creates an object
String name5 = new String("Socrates");
String name6 = name4;
Invoking Methods
 We've seen that once an object has been instantiated, we
can use the dot operator to invoke its methods
name.length()
 A method may return a value, which can be used in an
assignment or expression
count = name.length();
S.o.p(“Num. of char in “ + name+ “=“ + count);
 A method invocation can be thought of as asking an object
to perform a service
17
Object without object reference
cannot be accessed
18
String n1 = new String(“Ali“);
new String(“Abu“);
sv1: String
: String
value = “Ali”
value = “Abu”
n1
n1- object reference variable
Object References
 Primitive type variables ≠ object variables
19
References
 Note that a primitive variable contains the value
itself, but an object variable contains the address
of the object
 An object reference can be thought of as a pointer
to the location of the object
 Rather than dealing with arbitrary addresses, we
often depict a reference graphically
20
"Steve Jobs"name1
num1 38
Assignment Revisited
 The act of assignment takes a copy of a value
and stores it in a variable
 For primitive types:
21
num1 38
num2 96
Before:
num2 = num1;
num1 38
num2 38
After:
Object Reference
Assignment
 For object references, assignment copies the
address:
22
name2 = name1;
name1
name2
Before:
"Steve Jobs"
"Steve Austin"
name1
name2
After:
"Steve Jobs"
Questions
23
String stud1 = new String(“Ani”);
int studID = 65000;
What does variable stud1 contains?
What does variable studID contains?
Is this allowed? stud1 = studID;
String stud1;
stud1 = new String(“Ani”);
stud1 = new String(“Obi”);
How many objects were created by the program?
How many reference variables does the program contain?
Writing Classes
 The programs we’ve written in previous
examples have used classes defined in the Java
standard class library
 Now we will begin to design programs that rely
on classes that we write ourselves
 True object-oriented programming is based on
defining classes that represent objects with
well-defined characteristics and functionality
24
Graphical Representation of a
Class
25
The notation we used here is based on the industry standard notation
called UML, which stands for Unified Modeling Language.
A UML Class Diagram
Class Name
Variables
Method
Type of data
Access
Type of
return
value
A class can
contain data
declarations and
method
declarations
Object Instantiation
26
class
object
Object Design Questions
 What role will the object perform?
 What data or information will it need?
 Look for nouns.
 Which actions will it take?
 Look for verbs.
 What interface will it present to other objects?
 These are public methods.
 What information will it hide from other objects?
 These are private.
27
Design Specification for a
Rectangle
 Class Name: Rectangle
 Role: To represent a geometric rectangle
 States (Information or instance variables)
- Length: A variable to store rectangle’s length
(private)
- Width: A variable to store rectangle's width (private)
 Behaviors (public methods)
- Rectangle(): A constructor method to set a rectangle’s
length and width
- calculateArea(): A method to calculate a rectangle’s
area
28
UML Design Specification
29
UML Class Diagram
Class Name
What data does it need?
What behaviors
will it perform?
Public
methods
Hidden
information
Instance variables -- memory locations
used for storing the information needed.
Methods -- blocks of code used to
perform a specific task.
Method can has input (parameter) &
output (return value)
 Parameter : value given to method so that it can
do its task
 Can has 0 or more parameter
 Return value: A result that the method has
computed and returns it to the caller
 Can returns 0 or 1 value
 Eg. - pow(2,3)
- calculateArea()
- getBalance( )
- move( )
30
Continued…
Method Declarations
 A method declaration specifies the code that will
be executed when the method is invoked (called)
 When a method is invoked, the flow of control
jumps to the method and executes its code
 When complete, the flow returns to the place
where the method was called and continues
 The invocation may or may not return a value,
depending on how the method is defined
31
Method Control Flow
 If the called method is in the same class, only
the method name is needed
32
myMethod();
myMethodcompute
Method Control Flow
 The called method is often part of another
class or object
33
doIt helpMe
helpMe();obj.doIt();
main
Method Design
 What specific task will the method perform?
 What input data will it need to perform its
task?
 What result will the method produce?
 How input data are processed into result?
 What algorithm will the method use?
34
Method calculateArea()
Algorithm
 Method Name: calculateArea()
 Task: To calculate the area of a rectangle
 Data Needed (variables)
 length: A variable to store the rectangle's length
 width: A variable to store the rectangle's width
 area: A variable to store result of calculation
 Processing: area = length x width
 Result to be returned: area
35
Coding into Java
36
public class Rectangle // Class header
{
private double length; // Instance variables
private double width;
public Rectangle(double l, double w) // Constructor method
{
length = l;
width = w;
}
public double calculateArea() // calculate area method
{
double area;
area = length * width;
return area;
} // calculateArea()
} // Rectangle class
Method calculatePerimeter()
Algorithm
 Write an algorithm to calculate the perimeter
of a rectangle.
 Write the method in Java.
37
calculatePerimeter()
Algorithm
 Method Name: calculatePerimeter()
 Task: To calculate the perimeter of a
rectangle
 Data Needed (variables)
 length
 width
 perimeter
 Processing: perimeter = 2 x(length + width)
 Result to be returned: perimeter
38
calculatePerimeter() in Java
code
39
public double calculatePerimeter()
{
double perimeter;
perimeter = 2 * (length + width);
return perimeter;
} // calculatePerimeter()
Creating Rectangle Instances
 Create, or instantiate, two instances of the
Rectangle class:
40
The objects (instances)
store actual values.
Rectangle rectangle1 = new Rectangle(30,10);
Rectangle rectangle2 = new Rectangle(25, 20);
Using Rectangle Instances
 We use a method call to ask each object to tell
us its area:
41
rectangle1 area 300
rectangle2 area 500Printed output:
System.out.println("rectangle1 area " + rectangle1.calculateArea());
System.out.println("rectangle2 area " + rectangle2.calculateArea());
References to
objects
Method calls
Syntax : Object Construction
 new ClassName(parameters);
 Example:
 new Rectangle(30, 20);
 new Car("BMW 540ti", 2004);
 Purpose:
 To construct a new object, initialize it with the
construction parameters, and return a
reference to the constructed object.
42
The RectangleUser Class
Definition
public class RectangleUser
{
public static void main(String argv[])
{
Rectangle rectangle1 = new Rectangle(30,10);
Rectangle rectangle2 = new Rectangle(25,20);
System.out.println("rectangle1 area " +
rectangle1.calculateArea());
System.out.println("rectangle2 area " +
rectangle2.calculateArea());
} // main()
} // RectangleUser
43
An application must
have a main() method
Object
Use
Object
Creation
Class
Definition

More Related Content

What's hot

2CPP12 - Method Overriding
2CPP12 - Method Overriding2CPP12 - Method Overriding
2CPP12 - Method OverridingMichael Heron
 
Conditionalstatement
ConditionalstatementConditionalstatement
ConditionalstatementRaginiJain21
 
PYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.pptPYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.pptPriyaSoundararajan1
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04Spy Seat
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming LanguageExplore Skilled
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonparadisetechsoftsolutions
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiJuan Gomez
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Input output statement
Input output statementInput output statement
Input output statementsunilchute1
 

What's hot (20)

css.ppt
css.pptcss.ppt
css.ppt
 
Loops in C
Loops in CLoops in C
Loops in C
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
2CPP12 - Method Overriding
2CPP12 - Method Overriding2CPP12 - Method Overriding
2CPP12 - Method Overriding
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
Jsp
JspJsp
Jsp
 
Javascript
JavascriptJavascript
Javascript
 
PYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.pptPYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.ppt
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
STL in C++
STL in C++STL in C++
STL in C++
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of python
 
Teach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry PiTeach your kids how to program with Python and the Raspberry Pi
Teach your kids how to program with Python and the Raspberry Pi
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Input output statement
Input output statementInput output statement
Input output statement
 

Viewers also liked

Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationshipsPooja mittal
 
Parallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisParallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisManojit Nandi
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagramSadhana28
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objectsrahulsahay19
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 

Viewers also liked (10)

Object and class relationships
Object and class relationshipsObject and class relationships
Object and class relationships
 
Object and class
Object and classObject and class
Object and class
 
Parallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysisParallel Programming in Python: Speeding up your analysis
Parallel Programming in Python: Speeding up your analysis
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Class and object_diagram
Class  and object_diagramClass  and object_diagram
Class and object_diagram
 
Classes And Objects
Classes And ObjectsClasses And Objects
Classes And Objects
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
class and objects
class and objectsclass and objects
class and objects
 
C++ classes
C++ classesC++ classes
C++ classes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Similar to Class & Object - Intro

Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptxHailsh
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OOJohn Hunter
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsITNet
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 

Similar to Class & Object - Intro (20)

00-review.ppt
00-review.ppt00-review.ppt
00-review.ppt
 
07slide.ppt
07slide.ppt07slide.ppt
07slide.ppt
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Classes1
Classes1Classes1
Classes1
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Module 4.pptx
Module 4.pptxModule 4.pptx
Module 4.pptx
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Oop java
Oop javaOop java
Oop java
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptx
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Creating classes and applications in java
Creating classes and applications in javaCreating classes and applications in java
Creating classes and applications in java
 
Javascript foundations: Introducing OO
Javascript foundations: Introducing OOJavascript foundations: Introducing OO
Javascript foundations: Introducing OO
 
OOP Principles
OOP PrinciplesOOP Principles
OOP Principles
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
Ch.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objectsCh.1 oop introduction, classes and objects
Ch.1 oop introduction, classes and objects
 
34. uml
34. uml34. uml
34. uml
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 

More from PRN USM

Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2PRN USM
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1PRN USM
 
File Input & Output
File Input & OutputFile Input & Output
File Input & OutputPRN USM
 
Exception Handling
Exception HandlingException Handling
Exception HandlingPRN USM
 
Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2PRN USM
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1PRN USM
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control StructuresPRN USM
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And ExpressionPRN USM
 
Introduction To Computer and Java
Introduction To Computer and JavaIntroduction To Computer and Java
Introduction To Computer and JavaPRN USM
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...PRN USM
 
Empowering Women Towards Smokefree Homes
Empowering  Women  Towards  Smokefree  HomesEmpowering  Women  Towards  Smokefree  Homes
Empowering Women Towards Smokefree HomesPRN USM
 
Sfe The Singaporean Experience
Sfe The Singaporean ExperienceSfe The Singaporean Experience
Sfe The Singaporean ExperiencePRN USM
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...PRN USM
 
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesMalaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesPRN USM
 
Role Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlRole Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlPRN USM
 
Application Of Grants From Mhpb
Application Of Grants From MhpbApplication Of Grants From Mhpb
Application Of Grants From MhpbPRN USM
 

More from PRN USM (19)

Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2Graphical User Interface (GUI) - 2
Graphical User Interface (GUI) - 2
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Array
ArrayArray
Array
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And Expression
 
Introduction To Computer and Java
Introduction To Computer and JavaIntroduction To Computer and Java
Introduction To Computer and Java
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
 
Empowering Women Towards Smokefree Homes
Empowering  Women  Towards  Smokefree  HomesEmpowering  Women  Towards  Smokefree  Homes
Empowering Women Towards Smokefree Homes
 
Sfe The Singaporean Experience
Sfe The Singaporean ExperienceSfe The Singaporean Experience
Sfe The Singaporean Experience
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
 
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesMalaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
 
Role Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlRole Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco Control
 
Application Of Grants From Mhpb
Application Of Grants From MhpbApplication Of Grants From Mhpb
Application Of Grants From Mhpb
 

Recently uploaded

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 

Recently uploaded (20)

Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 

Class & Object - Intro

  • 2. Problem Solving  The key to designing a solution is breaking it down into manageable pieces  When writing software, we design separate pieces that are responsible for certain parts of the solution
  • 3.  Two popular programming design methods:  Structured Programming (SP)  Object-Oriented Programming (OOP) Problem Solving
  • 4. SP  Procedural based approach  Main problem will be divided into sub- problems  Analyze and refine each sub-problem  All sub-problem solutions are implemented as procedures and combined to solves the main problem
  • 5. Object-Oriented Programming  Object based approach  objects as foundation for problem solving  Identify objects from the main problem  An OOP program is a collection of objects that interacts each other
  • 6. Object-Oriented Programming  More natural way to solve problem  Objects can be used to represent real-world entities  For instance, an object might represent a particular employee in a company  Each employee object handles the processing and data management related to that employee
  • 7. Objects  Object-oriented programs use objects, which represent real world objects.  A real world object is a thing, both tangible and intangible.  An object has:  state (it has various properties, which might change)  behaviour (it can do things and can have things done to it) 7
  • 8. Objects  OOProgramming software objects  Software objects have state  Instance Variable/Data/Field  Software objects have behaviour  Method 8 Object’s members
  • 9. Objects interactions  OOP also involves interactions between objects through calling (invoking) of methods. 9 Method CallsThe OilSensor object calls the warning() method of the Controller, which then invokes the OilLight TurnOn() method.
  • 10. Method can Return Values  Return value: A result that the method has computed and returns it to the caller  Can returns 0 or 1 value Scanner s = new Scanner(System.in); int num = s.nextInt(); 10 Continued…
  • 11. Classes and Objects  To create an object , we MUST provide a definition/description for it  A class is a description/blue print of a kind of object  It does not by itself create any objects How to create an object ?  An object is called an instance of a class Object instantiation – process of creating an object 11
  • 12. Example of Java class: The String Class 12
  • 13. Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used as a type to declare an object reference variable String name;  No object is created with this declaration  An object reference variable holds the address of an object  The object itself must be created separately 13
  • 14. Creating Objects  Generally, we use the new operator to create an object 14 name = new String (“Ali bin Ahmad"); This calls the String constructor, which is a special method that sets up the object • Creating an object is called instantiation • An object is an instance of a particular class
  • 15. Constructing String objects Strings stringRef = new String(stringLiteral); eg. String name = new String(“Muhammad Haziq”); Since strings are used frequently, Java provides a shorthand notation for creating a string: String name = "Muhammad Haziq”; 15
  • 16. Constructing String objects  New String objects are created whenever the String constructors are used: 16 String name4 = new String(); // Creates an object String name5 = new String("Socrates"); String name6 = name4;
  • 17. Invoking Methods  We've seen that once an object has been instantiated, we can use the dot operator to invoke its methods name.length()  A method may return a value, which can be used in an assignment or expression count = name.length(); S.o.p(“Num. of char in “ + name+ “=“ + count);  A method invocation can be thought of as asking an object to perform a service 17
  • 18. Object without object reference cannot be accessed 18 String n1 = new String(“Ali“); new String(“Abu“); sv1: String : String value = “Ali” value = “Abu” n1 n1- object reference variable
  • 19. Object References  Primitive type variables ≠ object variables 19
  • 20. References  Note that a primitive variable contains the value itself, but an object variable contains the address of the object  An object reference can be thought of as a pointer to the location of the object  Rather than dealing with arbitrary addresses, we often depict a reference graphically 20 "Steve Jobs"name1 num1 38
  • 21. Assignment Revisited  The act of assignment takes a copy of a value and stores it in a variable  For primitive types: 21 num1 38 num2 96 Before: num2 = num1; num1 38 num2 38 After:
  • 22. Object Reference Assignment  For object references, assignment copies the address: 22 name2 = name1; name1 name2 Before: "Steve Jobs" "Steve Austin" name1 name2 After: "Steve Jobs"
  • 23. Questions 23 String stud1 = new String(“Ani”); int studID = 65000; What does variable stud1 contains? What does variable studID contains? Is this allowed? stud1 = studID; String stud1; stud1 = new String(“Ani”); stud1 = new String(“Obi”); How many objects were created by the program? How many reference variables does the program contain?
  • 24. Writing Classes  The programs we’ve written in previous examples have used classes defined in the Java standard class library  Now we will begin to design programs that rely on classes that we write ourselves  True object-oriented programming is based on defining classes that represent objects with well-defined characteristics and functionality 24
  • 25. Graphical Representation of a Class 25 The notation we used here is based on the industry standard notation called UML, which stands for Unified Modeling Language. A UML Class Diagram Class Name Variables Method Type of data Access Type of return value A class can contain data declarations and method declarations
  • 27. Object Design Questions  What role will the object perform?  What data or information will it need?  Look for nouns.  Which actions will it take?  Look for verbs.  What interface will it present to other objects?  These are public methods.  What information will it hide from other objects?  These are private. 27
  • 28. Design Specification for a Rectangle  Class Name: Rectangle  Role: To represent a geometric rectangle  States (Information or instance variables) - Length: A variable to store rectangle’s length (private) - Width: A variable to store rectangle's width (private)  Behaviors (public methods) - Rectangle(): A constructor method to set a rectangle’s length and width - calculateArea(): A method to calculate a rectangle’s area 28
  • 29. UML Design Specification 29 UML Class Diagram Class Name What data does it need? What behaviors will it perform? Public methods Hidden information Instance variables -- memory locations used for storing the information needed. Methods -- blocks of code used to perform a specific task.
  • 30. Method can has input (parameter) & output (return value)  Parameter : value given to method so that it can do its task  Can has 0 or more parameter  Return value: A result that the method has computed and returns it to the caller  Can returns 0 or 1 value  Eg. - pow(2,3) - calculateArea() - getBalance( ) - move( ) 30 Continued…
  • 31. Method Declarations  A method declaration specifies the code that will be executed when the method is invoked (called)  When a method is invoked, the flow of control jumps to the method and executes its code  When complete, the flow returns to the place where the method was called and continues  The invocation may or may not return a value, depending on how the method is defined 31
  • 32. Method Control Flow  If the called method is in the same class, only the method name is needed 32 myMethod(); myMethodcompute
  • 33. Method Control Flow  The called method is often part of another class or object 33 doIt helpMe helpMe();obj.doIt(); main
  • 34. Method Design  What specific task will the method perform?  What input data will it need to perform its task?  What result will the method produce?  How input data are processed into result?  What algorithm will the method use? 34
  • 35. Method calculateArea() Algorithm  Method Name: calculateArea()  Task: To calculate the area of a rectangle  Data Needed (variables)  length: A variable to store the rectangle's length  width: A variable to store the rectangle's width  area: A variable to store result of calculation  Processing: area = length x width  Result to be returned: area 35
  • 36. Coding into Java 36 public class Rectangle // Class header { private double length; // Instance variables private double width; public Rectangle(double l, double w) // Constructor method { length = l; width = w; } public double calculateArea() // calculate area method { double area; area = length * width; return area; } // calculateArea() } // Rectangle class
  • 37. Method calculatePerimeter() Algorithm  Write an algorithm to calculate the perimeter of a rectangle.  Write the method in Java. 37
  • 38. calculatePerimeter() Algorithm  Method Name: calculatePerimeter()  Task: To calculate the perimeter of a rectangle  Data Needed (variables)  length  width  perimeter  Processing: perimeter = 2 x(length + width)  Result to be returned: perimeter 38
  • 39. calculatePerimeter() in Java code 39 public double calculatePerimeter() { double perimeter; perimeter = 2 * (length + width); return perimeter; } // calculatePerimeter()
  • 40. Creating Rectangle Instances  Create, or instantiate, two instances of the Rectangle class: 40 The objects (instances) store actual values. Rectangle rectangle1 = new Rectangle(30,10); Rectangle rectangle2 = new Rectangle(25, 20);
  • 41. Using Rectangle Instances  We use a method call to ask each object to tell us its area: 41 rectangle1 area 300 rectangle2 area 500Printed output: System.out.println("rectangle1 area " + rectangle1.calculateArea()); System.out.println("rectangle2 area " + rectangle2.calculateArea()); References to objects Method calls
  • 42. Syntax : Object Construction  new ClassName(parameters);  Example:  new Rectangle(30, 20);  new Car("BMW 540ti", 2004);  Purpose:  To construct a new object, initialize it with the construction parameters, and return a reference to the constructed object. 42
  • 43. The RectangleUser Class Definition public class RectangleUser { public static void main(String argv[]) { Rectangle rectangle1 = new Rectangle(30,10); Rectangle rectangle2 = new Rectangle(25,20); System.out.println("rectangle1 area " + rectangle1.calculateArea()); System.out.println("rectangle2 area " + rectangle2.calculateArea()); } // main() } // RectangleUser 43 An application must have a main() method Object Use Object Creation Class Definition