Professional Documents
Culture Documents
Unit 1 Week 2 3 Jan.23 Feb4
Unit 1 Week 2 3 Jan.23 Feb4
23-Feb4, 2023)
UNIT 1 CONTENTS
Introduction to Object
Oriented Programming
Methods
OOP Basic Concepts
Aggregation
Composition
Machine Languages Assembly Languages High-Level Languages Procedural Languages Object-Oriented Languages (OOP)
Comprised of 1s and 0s It is a step towards easier High-level languages Early high-level languages are typically A programming language model in which is
The “native” language of programming. represent a giant leap called procedural languages. based upon the concept of objects which
a computer Comprised of a set of towards easier The program code is written as a contain data in the form of attributes and code
elemental commands programming. in the form of methods.
Difficult to program – sequence of instructions.
one misplaced 1 or 0 will which are tied to a specific The syntax of HL The focus of OOP languages is not on
processor. languages is similar to
User has to specify “what to do” and also
cause the program to “how to do” (step by step procedure). structure, but on modeling data.
fail. Codes need to be English.
These instructions are executed in the In object-oriented programming, computer
Coding example: translated to machine Example: programs are designed using the concept of
language before the sequential order. These instructions are
grossPay = basePay + overTimePay objects that interact with the real world.
1110100010101 computer processes it. written to solve specific problems.
HL Languages is divided Programmers code using “blueprints” of data
111010101110 Coding Example: into 2 groups: Examples include C, COBOL, Pascal,
HTML, VBScript models called classes.
11110111 Divide 1001010, 1011010 - Procedural Languages Examples of OOP languages include C++, Visual
- Object-Oriented Basic.NET, Java and Python
5 Programming (OOP) By: JMI 6 By: JMI
Example:
Procedural Languages Object-Oriented Languages (OOP)
Above example is a Procedural approach for solving problem, because it creates different
methods for calculating areas of different geometries.
Identify if Procedural or Object Oriented Language : Identify if Procedural or Object Oriented Language :
Above example will remain procedural, even if it uses an object. It still have sequence of
instructions, and functions for accomplishing / solving the problem.
Object-Oriented
Programming (OOP)
13 By: JMI 14
“
Key idea in object-oriented :
The real world can be “accurately” described as a
OOP
Basic Terminologies
collection of objects that interact.
17 18
OBJECTS OBJECTS
Informally, an object represents an entity, either physical, conceptual, or In a more formal definition, an
software.
object is a computational entity
that:
Physical Entity Conceptual Entity Software Entity 1. Encapsulates some state
2. Is able to perform actions,
or methods, on this state
3. Communicates with other
objects via message passing
OBJECTS OBJECTS
Characteristics of Objects: Real World Object: Almost everything in the world can be represented as an object :
1. decomposition of programs into a number • A flower, a tree, an animal
of entities
• A student, a professor
2. consist of data and function
• A desk, a chair, a classroom, a building
3. data of an object can be accessed only by
the functions associated with that object • A university, a city, a country
An object consists of data and behavior. • The world, the universe
The data and behavior comprise an • A subject such as Calculus, Advance Math, History, …
interface, which specifies how the object
may be utilized by any of various • An information system, financial, legal, etc..
consumers of the object.
21 By: JMI 22 By: JMI
CLASS METHODS
A class is a prototype, idea, and A method in object-oriented programming (OOP) is a procedure associated with a
blueprint for creating objects message and an object.
Class is composed of three things: Many kinds of methods exist, but support for them varies across languages. Some types
its name, attributes/properties, and of methods are created and called by programmer code, while other special methods—
methods. such as constructors, destructors, and conversion operators—are created and called by
compiler-generated code. A language may also allow the programmer to define and call
An object is an instance of a class. In these special methods.
Java or Python, we define classes,
Three types of method:
which in turn are used to create
1. Accessor methods - used to read data values of an object
objects.
2.Mutator methods - used to modify the data of an object
A class is a definition of objects with
the same properties and the same 3.Manager methods - used to initialize and destroy objects of a class,
methods. e.g. constructors and destructors
23 By: JMI 24 By: JMI
ENCAPSULATION
Hides the details of the implementation of an
objects.
BENEFITS:
Ensures that structural changes remain local:
- Changing the class internals does not affect any code outside of the class
- Changing methods' implementation does not reflect the clients using them We defined a Computer class.
We used __init__() method to store the maximum
Hiding implementation details reduces complexity selling price of Computer.
We tried to modify the price. However, we can't
- easier maintenance change it because Python treats the __maxprice as
private attributes.
EXAMPLE: As shown, to change the value, we have to use a
setter function i.e setMaxPrice() which takes price
as a parameter.
User and a Mobile phone - “User don't need to know the internal functionality of the Therefore,
mobile phone to operate it, it has an interface to use the device behavior without knowing
Encapsulation prevents data from direct
implementation details. (other example: calculator, ATM machine etc.)
modification;
ABSTRACTION ABSTRACTION
Therefore,
Inheritance is a way of creating a
BENEFITS: new class for using details of an
existing class without modifying it.
The newly formed class is a derived
Expresses commonality class (or child class). Similarly, the
among classes/objects existing class is a base class (or
parent class).
Allows code reusability
Highlights relationships we created two classes i.e. Bird (parent class) and Penguin (child class).
The child class inherits the functions of parent class. We can see this from
Helps in code the swim() method.
organization Again, the child class modified the behavior of the parent class. We can
see this from the whoisThis() method. Furthermore, we extend the
functions of the parent class, by creating a new run() method.
Additionally, we use the super() function inside the __init__() method.
This allows us to run the __init__() method of the parent class inside the
child class.
POLYMORPHISM POLYMORPHISM
PROGRAMMING CONCEPTS
UNIFIED MODELING
If a programmer has preventing loss of data. will not be converted to
already written a power machine code. This mark
up can be as long as the
LANGUAGE (UML)
function, then it should
be written that any programmer wants, and
program can make a call allows for comprehensive
to that function and it information to be passed
should work exactly the on to new programmers.
same. This is important for both
the re-usability and the
maintainability of
programs.
41 42
CLASSES CLASSES
CLASSES CLASSES
CLASSES ENUMERATION
Association Relationships An enumeration is a user-defined data type that consists of a name and an
We can indicate the multiplicity of an association by adding multiplicity ordered list of enumeration literals.
adornments to the line denoting the association.
Thanks!
any
questions
?
You can directly message me at my FB Account:
jeanne macapagal imbuido
59