SlideShare uma empresa Scribd logo
1 de 36
Workshop on
Object-oriented programming
FAHAD HUSSAIN
MCS, MSCS, DAE(CIT)
Computer Science Instructor of well known international Center
Also, Machine Learning and Deep learning Practitioner
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Object-oriented programming
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Object-oriented programming (OOP) is a programming paradigm based on the
concept of "objects", which can contain data, in the form of fields (often known
as attributes or properties), and code, in the form of procedures (often known as
methods). It is the programming concept based on bottom-up approach!
The main aim of OOP is to bind together the data and the functions that operate
on them so that no other part of the code can access this data except that
function.
Object-oriented programming
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Pillars of object-oriented programming
1)Encapsulation:
2)Inheritance:
3)Polymorphism:
4)Abstraction:
5)*Exception Handling
Class ,Object and Function/Method
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Before going into depth in OOP, let’s understand the 6 basic things!
1. What is class
2. What is object
3. What is namespaces
4. What is function/Method
5. What is Constructor and its types
6. What is Destructors
Class ,Object and Function/Method
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Class:
It is a user-defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class. A class is like a blueprint for an object.
In simple words, it is a prototype or building block structure for starting work in the OOP
approach!
Object:
An Object is an identifiable entity with some characteristics and behavior. An Object is an
instance of a Class. When a class is defined, no memory is allocated but when it is
instantiated (i.e. an object is created) memory is allocated.
Class ,Object and Function/Method
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Function VS Method:
A method is a code block that contains a series of statements according to the requirement
of the program! In OOP = Method and in procedure = Function
Namespaces
Namespaces in C# are used to organize too many classes so that it can be easy to handle the
application. We use System.Console where System is the namespace and Console is the
class. To access the class of a namespace, we need to use namespacename.classname. We
can use using keyword so that we don't have to use complete name all the time.
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
A constructor is a special method of the class which gets automatically invoked whenever an instance of
the class is created. Like methods, a constructor also contains the collection of instructions that are
executed at the time of Object creation. It is used to assign initial values to the data members of the
same class.
Types of Constructor
• Default Constructor
• Parametrized Constructor (with overload concept)
• Copy Constructor
• Private Constructor
• Static Constructor
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Default Constructor
A constructor with no parameters is called a default
constructor. A default constructor has every instance of
the class to be initialized to the same values. The
default constructor initializes all numeric fields to zero
and all string and object fields to null inside a class.
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Parameterized Constructor with overload
A constructor have at least one parameter is called
a parametrized constructor. It can initialize each
instance of the class to different values.
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Copy Constructor
This constructor will creates an object by copying
variables from another object. Its main use is to
initialize a new instance to the values of an existing
instance.
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Private Constructor
If a constructor is created with private specifier is known as Private
Constructor. It is not possible for other classes to derive from this
class and also it’s not possible to create an instance of this class.
Points To Remember :
use private constructor when we have only static members.
Using private constructor, prevents the creation of the instances of
that class.
Constructor and its types
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Static Constructor (no access modifier, no parameters)
Static Constructor has to be invoked only once in the class and it has been
invoked during the creation of the first reference to a static member in the class.
A static constructor is initialized static fields or data of the class and to be
executed only once.
Points To Remember :
It can’t be called directly.
When it is executing then the user has no control.
It does not take access modifiers or any parameters.
It is called automatically to initialize the class before the first instance created.
Constructor
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Important points to Remember About Constructors
• Constructor of a class must have the same name as the class name in
which it resides.
• A constructor can not be abstract, final, and Synchronized.
• Within a class, you can create only one static constructor.
• A constructor doesn’t have any return type, not even void.
• A static constructor cannot be a parameterized constructor.
• A class can have any number of constructors.
• Access modifiers can be used in constructor declaration to control its
access i.e. which other class can call the constructor.
Destructors
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Destructors in C# are methods inside the class used to destroy instances of that
class when they are no longer needed. The Destructor is called implicitly by the
.NET Framework's Garbage collector and therefore programmer has no control as
when to invoke the destructor
• In c#, destructors can be used only in classes and a class can contain only one destructor.
• The destructor in class can be represented by using tilde (~) operator
• The destructor in c# won’t accept any parameters and access modifiers.
• The destructor will invoke automatically, whenever an instance of class is no longer needed.
• The destructor automatically invoked by garbage collector whenever the class objects that
are no longer needed in application.
Till Now, We have Learn!
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
What is class
What is object
What is namespaces
What is function/Method
What is Constructor and its types
What is Destructor
Theory + Practical in C#,
Thank you Very Much, end of Workshop Part 1
Now, next we will discuss about the pillars from scratch!
Workshop on
Object-oriented programming
FAHAD HUSSAIN
MCS, MSCS, DAE(CIT)
Computer Science Instructor of well known international Center
Also, Machine Learning and Deep learning Practitioner
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Workshop Part 2
Till Now, We have Learn!
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
What is class
What is object
What is namespaces
What is function/Method
What is Constructor and its types
What is Destructor
Workshop Part 1
Object-oriented programming
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Pillars of object-oriented programming
1)Encapsulation:
2)Inheritance:
3)Polymorphism:
4)Abstraction:
5)*Exception Handling
Encapsulation
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
In object-oriented programming, encapsulation refers to the
bundling of data with the methods that operate on that data,
or the restricting of direct access to some of an object's
components.
Encapsulation, its can be accessed/done by Access Modifier /
Access Specifier
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Access modifiers (or access specifiers) are keywords in object-oriented
languages that set the accessibility of classes, methods, and other members. Access
modifiers are a specific part of programming language syntax used to facilitate the
encapsulation of components.
In the C#, there are Six access Modifier whereas just for information 4 in Java!
1. Public: The type or member can be accessed by any other code in the same assembly or another assembly that
references it.
2. Private: The type or member can be accessed only by code in the same class or struct.
3. Protected: The type or member can be accessed only by code in the same class, or in a class that is derived from
that class.
4. Internal : The type or member can be accessed by any code in the same assembly, but not from another assembly.
5. Protected Internal : The type or member can be accessed by any code in the assembly in which it is declared, or
from within a derived class in another assembly.
6. Private Protected: It access modifier is a combination of the private and protected keywords. We can access
members inside the containing class or in a class that derives from a containing class, but only in the same
assembly(project). Therefore, if we try to access it from another assembly, we will get an error. (C# 7.0)
In Java
Public Private Protected Default
Inheritance
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Object-Oriented programming language is code reuse. This reusability is possible due to the
relationship b/w the classes. Object oriented programming generally support 4 types of
relationships that are: inheritance , association, composition and aggregation. All these
relationship is based on "is a" relationship, "has-a" relationship and "part-of" relationship.
Inheritance
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Also, multiple and hybrid level, (preform by interface)
because in C#, and Java these are not allowed using
inheritance!
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Has a relationship:
Association is relation between two separate classes which establishes through
their Objects. Association can be one-to-one, one-to-many, many-to-one, many-to-
many.
In Object-Oriented programming, an Object communicates to other Object to use
functionality and services provided by that object. Composition and Aggregation are
the two forms of association.
Student has a ID, name etc…
also with new keyword!
Polymorphism
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
The word polymorphism means having many forms. In
object-oriented programming paradigm, polymorphism is
often expressed as 'one interface, multiple functions’.
Polymorphism
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Function Overloading
You can have multiple definitions for the same function name in the
same scope. The definition of the function must differ from each
other by the types and/or the number of arguments in the argument
list. You cannot overload function declarations that differ only by
return type.
Polymorphism
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Operator overloading:
The concept of overloading a function can also be applied
to operators. Operator overloading gives the ability to use
the same operator to do various operations.
Let’s understand the concept of + in the code…
Till Now, We have Learn!
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
1)What is Encapsulation:
2)Inheritance:
3)Polymorphism (only static or compile time)
Theory + Practical in C#,
Thank you Very Much, end of Workshop Part 2
Now, next we will discuss about the pillars (rest of the) from
scratch in the Last Session (Part 3)!
Workshop on
Object-oriented programming
FAHAD HUSSAIN
MCS, MSCS, DAE(CIT)
Computer Science Instructor of well known international Center
Also, Machine Learning and Deep learning Practitioner
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Workshop Part 3
Till Now, We have Learn!
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
What is class
What is object
What is namespaces
What is
function/Method
What is Constructor
and its types
What is Destructor
Workshop Part 1
1)What is Encapsulation:
2)Inheritance:
3)Polymorphism (only static
or compile time)
Workshop Part 2
Polymorphism
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
The word polymorphism means having many forms. In
object-oriented programming paradigm, polymorphism is
often expressed as 'one interface, multiple functions’.
Method Override … Method Hiding
Polymorphism
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Method Hiding:
For hiding the base class method from derived class
simply declare the derived class method with the new
keyword.
Method Overriding
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Run Time Polymorphism means overriding a base class method in
derived class by creating a similar function and this can be achieved
by using override & virtual keywords along
with inheritance principle.
By using run time polymorphism, we can override a base
class method in derived class by creating a method with same name
and parameters to perform a different task.
In c#, the run time polymorphism can be achieved by using method
overriding and it is also called as late binding or dynamic binding.
Abstraction
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Abstraction is the detail hiding of (implementation hiding).
Abstraction will be done by: Abstract class
• By using Abstraction you can used abstraction 0
to 100%!!!
Abstraction
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
Interface (It is special type of class but not exactly
class, containing the abstract method only) also used
for multiple inheritance in C#.
• By using Interface you can used abstraction
100%!!!
• Also, Interface used for multiple level
inheritance in C#, Java!
Exception Handling
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
 try – A try block is used to encapsulate a region of code. If any code throws an exception within that try
block, the exception will be handled by the corresponding catch.
 catch – When an exception occurs, the Catch block of code is executed. This is where you are able to
handle the exception, log it, or ignore it.
 finally – The finally block allows you to execute certain code if an exception is thrown or not. For
example, disposing of an object that must be disposed of.
 throw – The throw keyword is used to actually create a new exception that is the bubbled up to a try
catch finally block.
The try catch and finally block is a mechanism to detect and handle run-time errors in code.
It is provided by one of the built-in classes for common exceptions. The exceptions are anomalies that
occur during the execution of a program. They can be because of user, logic or system errors. If a user
(programmer) does not provide a mechanism to handle these anomalies, the compiler provide a default
mechanism, which terminates the program execution.
Finally
For further assistance, code and slide https://fahadhussaincs.blogspot.com/
What is class
What is object
What is namespaces
What is function/Method
What is Constructor and
its types
What is Destructor
Workshop Day 1, Part 1
1)What is Encapsulation:
2)Inheritance:
3)Polymorphism
(only static or compile time)
Workshop Day 2, Part 2
1)Polymorphism
(only static or compile time)
2) Abstraction VS interface
3) Exception Handling
Workshop Day 3, Part 3
Thank you very much to stay with me!

Mais conteúdo relacionado

Semelhante a Object-oriented programming 3.pptx

Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#Muhammad Younis
 
Understanding class, object & interface
Understanding class, object & interfaceUnderstanding class, object & interface
Understanding class, object & interfaceMD. Shohag Mia
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesDurgesh Singh
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersSanjaya Prakash Pradhan
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceEng Teong Cheah
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented ProgrammingGamindu Udayanga
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 

Semelhante a Object-oriented programming 3.pptx (20)

Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
Understanding class, object & interface
Understanding class, object & interfaceUnderstanding class, object & interface
Understanding class, object & interface
 
Classes2
Classes2Classes2
Classes2
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Java basics
Java basicsJava basics
Java basics
 
Oopsinphp
OopsinphpOopsinphp
Oopsinphp
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Object-oriented programming 3.pptx

  • 1. Workshop on Object-oriented programming FAHAD HUSSAIN MCS, MSCS, DAE(CIT) Computer Science Instructor of well known international Center Also, Machine Learning and Deep learning Practitioner For further assistance, code and slide https://fahadhussaincs.blogspot.com/
  • 2. Object-oriented programming For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data, in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods). It is the programming concept based on bottom-up approach! The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
  • 3. Object-oriented programming For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Pillars of object-oriented programming 1)Encapsulation: 2)Inheritance: 3)Polymorphism: 4)Abstraction: 5)*Exception Handling
  • 4. Class ,Object and Function/Method For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Before going into depth in OOP, let’s understand the 6 basic things! 1. What is class 2. What is object 3. What is namespaces 4. What is function/Method 5. What is Constructor and its types 6. What is Destructors
  • 5. Class ,Object and Function/Method For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Class: It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A class is like a blueprint for an object. In simple words, it is a prototype or building block structure for starting work in the OOP approach! Object: An Object is an identifiable entity with some characteristics and behavior. An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated.
  • 6. Class ,Object and Function/Method For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Function VS Method: A method is a code block that contains a series of statements according to the requirement of the program! In OOP = Method and in procedure = Function Namespaces Namespaces in C# are used to organize too many classes so that it can be easy to handle the application. We use System.Console where System is the namespace and Console is the class. To access the class of a namespace, we need to use namespacename.classname. We can use using keyword so that we don't have to use complete name all the time.
  • 7. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ A constructor is a special method of the class which gets automatically invoked whenever an instance of the class is created. Like methods, a constructor also contains the collection of instructions that are executed at the time of Object creation. It is used to assign initial values to the data members of the same class. Types of Constructor • Default Constructor • Parametrized Constructor (with overload concept) • Copy Constructor • Private Constructor • Static Constructor
  • 8. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Default Constructor A constructor with no parameters is called a default constructor. A default constructor has every instance of the class to be initialized to the same values. The default constructor initializes all numeric fields to zero and all string and object fields to null inside a class.
  • 9. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Parameterized Constructor with overload A constructor have at least one parameter is called a parametrized constructor. It can initialize each instance of the class to different values.
  • 10. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Copy Constructor This constructor will creates an object by copying variables from another object. Its main use is to initialize a new instance to the values of an existing instance.
  • 11. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Private Constructor If a constructor is created with private specifier is known as Private Constructor. It is not possible for other classes to derive from this class and also it’s not possible to create an instance of this class. Points To Remember : use private constructor when we have only static members. Using private constructor, prevents the creation of the instances of that class.
  • 12. Constructor and its types For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Static Constructor (no access modifier, no parameters) Static Constructor has to be invoked only once in the class and it has been invoked during the creation of the first reference to a static member in the class. A static constructor is initialized static fields or data of the class and to be executed only once. Points To Remember : It can’t be called directly. When it is executing then the user has no control. It does not take access modifiers or any parameters. It is called automatically to initialize the class before the first instance created.
  • 13. Constructor For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Important points to Remember About Constructors • Constructor of a class must have the same name as the class name in which it resides. • A constructor can not be abstract, final, and Synchronized. • Within a class, you can create only one static constructor. • A constructor doesn’t have any return type, not even void. • A static constructor cannot be a parameterized constructor. • A class can have any number of constructors. • Access modifiers can be used in constructor declaration to control its access i.e. which other class can call the constructor.
  • 14. Destructors For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Destructors in C# are methods inside the class used to destroy instances of that class when they are no longer needed. The Destructor is called implicitly by the .NET Framework's Garbage collector and therefore programmer has no control as when to invoke the destructor • In c#, destructors can be used only in classes and a class can contain only one destructor. • The destructor in class can be represented by using tilde (~) operator • The destructor in c# won’t accept any parameters and access modifiers. • The destructor will invoke automatically, whenever an instance of class is no longer needed. • The destructor automatically invoked by garbage collector whenever the class objects that are no longer needed in application.
  • 15. Till Now, We have Learn! For further assistance, code and slide https://fahadhussaincs.blogspot.com/ What is class What is object What is namespaces What is function/Method What is Constructor and its types What is Destructor Theory + Practical in C#, Thank you Very Much, end of Workshop Part 1 Now, next we will discuss about the pillars from scratch!
  • 16. Workshop on Object-oriented programming FAHAD HUSSAIN MCS, MSCS, DAE(CIT) Computer Science Instructor of well known international Center Also, Machine Learning and Deep learning Practitioner For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Workshop Part 2
  • 17. Till Now, We have Learn! For further assistance, code and slide https://fahadhussaincs.blogspot.com/ What is class What is object What is namespaces What is function/Method What is Constructor and its types What is Destructor Workshop Part 1
  • 18. Object-oriented programming For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Pillars of object-oriented programming 1)Encapsulation: 2)Inheritance: 3)Polymorphism: 4)Abstraction: 5)*Exception Handling
  • 19. Encapsulation For further assistance, code and slide https://fahadhussaincs.blogspot.com/ In object-oriented programming, encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object's components. Encapsulation, its can be accessed/done by Access Modifier / Access Specifier
  • 20. For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Access modifiers (or access specifiers) are keywords in object-oriented languages that set the accessibility of classes, methods, and other members. Access modifiers are a specific part of programming language syntax used to facilitate the encapsulation of components. In the C#, there are Six access Modifier whereas just for information 4 in Java! 1. Public: The type or member can be accessed by any other code in the same assembly or another assembly that references it. 2. Private: The type or member can be accessed only by code in the same class or struct. 3. Protected: The type or member can be accessed only by code in the same class, or in a class that is derived from that class. 4. Internal : The type or member can be accessed by any code in the same assembly, but not from another assembly. 5. Protected Internal : The type or member can be accessed by any code in the assembly in which it is declared, or from within a derived class in another assembly. 6. Private Protected: It access modifier is a combination of the private and protected keywords. We can access members inside the containing class or in a class that derives from a containing class, but only in the same assembly(project). Therefore, if we try to access it from another assembly, we will get an error. (C# 7.0) In Java Public Private Protected Default
  • 21. Inheritance For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Object-Oriented programming language is code reuse. This reusability is possible due to the relationship b/w the classes. Object oriented programming generally support 4 types of relationships that are: inheritance , association, composition and aggregation. All these relationship is based on "is a" relationship, "has-a" relationship and "part-of" relationship.
  • 22. Inheritance For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Also, multiple and hybrid level, (preform by interface) because in C#, and Java these are not allowed using inheritance!
  • 23. For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Has a relationship: Association is relation between two separate classes which establishes through their Objects. Association can be one-to-one, one-to-many, many-to-one, many-to- many. In Object-Oriented programming, an Object communicates to other Object to use functionality and services provided by that object. Composition and Aggregation are the two forms of association. Student has a ID, name etc… also with new keyword!
  • 24. Polymorphism For further assistance, code and slide https://fahadhussaincs.blogspot.com/ The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as 'one interface, multiple functions’.
  • 25. Polymorphism For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Function Overloading You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.
  • 26. Polymorphism For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Operator overloading: The concept of overloading a function can also be applied to operators. Operator overloading gives the ability to use the same operator to do various operations. Let’s understand the concept of + in the code…
  • 27. Till Now, We have Learn! For further assistance, code and slide https://fahadhussaincs.blogspot.com/ 1)What is Encapsulation: 2)Inheritance: 3)Polymorphism (only static or compile time) Theory + Practical in C#, Thank you Very Much, end of Workshop Part 2 Now, next we will discuss about the pillars (rest of the) from scratch in the Last Session (Part 3)!
  • 28. Workshop on Object-oriented programming FAHAD HUSSAIN MCS, MSCS, DAE(CIT) Computer Science Instructor of well known international Center Also, Machine Learning and Deep learning Practitioner For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Workshop Part 3
  • 29. Till Now, We have Learn! For further assistance, code and slide https://fahadhussaincs.blogspot.com/ What is class What is object What is namespaces What is function/Method What is Constructor and its types What is Destructor Workshop Part 1 1)What is Encapsulation: 2)Inheritance: 3)Polymorphism (only static or compile time) Workshop Part 2
  • 30. Polymorphism For further assistance, code and slide https://fahadhussaincs.blogspot.com/ The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as 'one interface, multiple functions’. Method Override … Method Hiding
  • 31. Polymorphism For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Method Hiding: For hiding the base class method from derived class simply declare the derived class method with the new keyword.
  • 32. Method Overriding For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Run Time Polymorphism means overriding a base class method in derived class by creating a similar function and this can be achieved by using override & virtual keywords along with inheritance principle. By using run time polymorphism, we can override a base class method in derived class by creating a method with same name and parameters to perform a different task. In c#, the run time polymorphism can be achieved by using method overriding and it is also called as late binding or dynamic binding.
  • 33. Abstraction For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Abstraction is the detail hiding of (implementation hiding). Abstraction will be done by: Abstract class • By using Abstraction you can used abstraction 0 to 100%!!!
  • 34. Abstraction For further assistance, code and slide https://fahadhussaincs.blogspot.com/ Interface (It is special type of class but not exactly class, containing the abstract method only) also used for multiple inheritance in C#. • By using Interface you can used abstraction 100%!!! • Also, Interface used for multiple level inheritance in C#, Java!
  • 35. Exception Handling For further assistance, code and slide https://fahadhussaincs.blogspot.com/  try – A try block is used to encapsulate a region of code. If any code throws an exception within that try block, the exception will be handled by the corresponding catch.  catch – When an exception occurs, the Catch block of code is executed. This is where you are able to handle the exception, log it, or ignore it.  finally – The finally block allows you to execute certain code if an exception is thrown or not. For example, disposing of an object that must be disposed of.  throw – The throw keyword is used to actually create a new exception that is the bubbled up to a try catch finally block. The try catch and finally block is a mechanism to detect and handle run-time errors in code. It is provided by one of the built-in classes for common exceptions. The exceptions are anomalies that occur during the execution of a program. They can be because of user, logic or system errors. If a user (programmer) does not provide a mechanism to handle these anomalies, the compiler provide a default mechanism, which terminates the program execution.
  • 36. Finally For further assistance, code and slide https://fahadhussaincs.blogspot.com/ What is class What is object What is namespaces What is function/Method What is Constructor and its types What is Destructor Workshop Day 1, Part 1 1)What is Encapsulation: 2)Inheritance: 3)Polymorphism (only static or compile time) Workshop Day 2, Part 2 1)Polymorphism (only static or compile time) 2) Abstraction VS interface 3) Exception Handling Workshop Day 3, Part 3 Thank you very much to stay with me!