Programming Paradigms: OOP, Functional, Procedural

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which programming paradigm focuses on declarations and expressions, aiming for clear, understandable code by avoiding traditional flow-control statements?

  • Functional Programming (correct)
  • Procedural Programming
  • Object-Oriented Programming
  • Imperative Programming

In Object-Oriented Programming (OOP), what is the primary role of a class?

  • To manage data abstraction
  • To execute operations in a sequence
  • To build programs focusing on expressions
  • To serve as a blueprint for creating objects (correct)

Which of the following best describes the concept of 'Data Encapsulation' in Object-Oriented Programming?

  • Creating classes that share attributes and methods of existing classes
  • Defining the attributes and behaviors of objects
  • Wrapping up data and functions into a single class to hide data (correct)
  • Including only essential details of an entity without background details

What is the main characteristic of Procedural Programming?

<p>Operations are executed one after another in a sequence (D)</p> Signup and view all the answers

Which of the following demonstrates the concept of 'Inheritance' in OOP?

<p>Creating a new class based on an existing class, inheriting its properties and methods (B)</p> Signup and view all the answers

In OOP, which term describes a self-contained block of program code that carries out actions, similar to a procedure?

<p>Method (C)</p> Signup and view all the answers

What does 'Data Abstraction' primarily achieve in OOP?

<p>Hiding complex implementation details and showing only essential information (A)</p> Signup and view all the answers

Which of the following languages is NOT primarily associated with Functional Programming?

<p>Java (B)</p> Signup and view all the answers

Which of the following access modifiers allows any other class to utilize a method or variable?

<p>public (C)</p> Signup and view all the answers

Suppose a method is defined as static. What is the implication of this keyword?

<p>The method can be used without instantiating an object of the class. (C)</p> Signup and view all the answers

What is the primary function of accessor methods (getters) within a class?

<p>To retrieve the values of data fields. (D)</p> Signup and view all the answers

In object-oriented programming, what term describes the ability of a single name or symbol to represent different types or behaviors depending on the context?

<p>Polymorphism (D)</p> Signup and view all the answers

A class named Vehicle has a subclass named Car. Which of the following statements is true?

<p><code>Car</code> inherits properties from <code>Vehicle</code>. (B)</p> Signup and view all the answers

What is the role of a constructor in object-oriented programming?

<p>To create and initialize objects of a class. (A)</p> Signup and view all the answers

Consider a method defined in a class with a void return type. What does this indicate about the method's operation?

<p>The method does not return any value. (C)</p> Signup and view all the answers

What is the purpose of mutator methods (setters) in a class?

<p>To set or change the values of data fields. (A)</p> Signup and view all the answers

Flashcards

Derived Class

A class that inherits properties from another class.

Polymorphism

Having many forms; allows same word/symbol to be interpreted correctly.

Operator Overloading

Making an operator perform different tasks in different situations.

Function Overloading

Two or more functions with the same name but different parameters.

Signup and view all the flashcards

Method

A reusable block of code that performs a specific task.

Signup and view all the flashcards

Public Access Modifier

Allows any class to use it.

Signup and view all the flashcards

Static Method

A method that can be used without creating an object of the class.

Signup and view all the flashcards

Constructor

A special method that creates and initializes objects.

Signup and view all the flashcards

Programming Paradigm

A way of structuring and organizing code; a synonym for 'pattern'.

Signup and view all the flashcards

Procedural Programming

Executes operations in sequence, grouped logically into procedures (functions, modules, etc.).

Signup and view all the flashcards

Functional Programming

Focuses on declarations and expressions, avoiding flow-control statements for clarity.

Signup and view all the flashcards

Object-Oriented Programming (OOP)

An extension of procedural programming using objects as building blocks to model real-world entities.

Signup and view all the flashcards

Class (in OOP)

A blueprint for creating objects, defining their attributes and behaviors.

Signup and view all the flashcards

Object (in OOP)

A specific instance of a class, with identifiable characteristics and behavior.

Signup and view all the flashcards

Method (in OOP)

A self-contained block of code that performs a specific action, similar to a procedure.

Signup and view all the flashcards

Data Encapsulation

Wrapping data and functions together into a class, hiding data for security.

Signup and view all the flashcards

Study Notes

  • Object-oriented Programming (OOP) is one of three programming paradigms, along with Procedural and Functional Programming.
  • A programming paradigm structures and organizes code.
  • The term "paradigm" is synonymous with "pattern."

Procedural Programming

  • Languages include Basic, C, C++, and Pascal.
  • Operations are executed sequentially.
  • It uses and defines variables to hold data.
  • Procedures are grouped logical units based on operations.
  • Procedures are functions, modules, subroutines, and methods that Java programmers use.

Functional Programming

  • Languages include Erlang, Scala, Haskell, and Elm.
  • Focuses on declarations and expressions rather than statement execution.
  • Functional programming intends to write clear code.
  • Flow-control statements like 'for', 'while', 'break', 'continue', and 'goto' are avoided.
  • Functions are the main units of this paradigm.

Object-Oriented Programming (OOP)

  • It extends procedural programming.
  • Objects, representing real-world models, are the building blocks.
  • OOP involves creating classes (blueprints), objects (instances), and applications to manipulate those objects.
  • Java, Python, VB.NET, and C# support this paradigm.

Procedural vs. Object-Oriented Programming Naming Conventions

  • Variables in procedural become objects in OOP.
  • User-defined data types in procedural become classes.
  • Structured members become instance variables.
  • Functions become methods.
  • Function calls turn into message passing.

Procedural vs. Object-Oriented Programming Differences

  • Procedural programming emphasizes procedures over data, while OOP emphasizes data.
  • Data securitization is not a feature of Procedural programming, while data is considered secure in OOP.
  • Procedural programming uses a top-down approach, and OOP employs a bottom-up approach.
  • Procedural programming doesn't model real-world entities, but OOP does.
  • Procedural programming decomposes programs into functions or procedures, where OOP decomposes them into objects.

Advantages of OOP

  • Code is modularized using classes and objects.
  • Code duplication is reduced, and reusability is increased through linking code and shared objects.
  • Data security is ensured by encapsulating data with functions.
  • Program complexity is reduced via inheritance.
  • Creation and implementation is faster.

OOP Concepts

Class

  • A group or collection of objects sharing common properties.
  • It serves as the basic unit of programming.
  • A class definition describes the attributes and actions of its objects.
  • An attribute serves as a property of the object.

Object

  • A specific and concrete instance of a class.
  • This identifiable entity has characteristics and behavior.
  • Features are called data members and operations called function members.

Method

  • A self-contained block of code performs actions similar to a procedure in Procedural Programming.

Relating Classes, Methods, and Objects

  • Automobile (class) has make/model/year/color (objects) and can move forward/backward and check gas status (methods).
  • Dog (class) has breed/name/age/vaccine (objects) and can walk/eat/recognize names (methods).
  • Object's class helps understand its characteristics; for example, a friend purchasing an automobile ensures it has a model name (object).

Data Abstraction

  • Essential details of an entity are included, excluding background details.
  • This hidden information is abstracted data.

Data Encapsulation

  • This is wrapping data and functions into a class.
  • It performs data hiding.

Inheritance

  • This enables classes to share attributes and methods with more specific features.
  • A base/parent/superclass is the class that other classes inherit properties from.
  • A derived/child/subclass is the class inheriting properties from another.

Polymorphism

  • "Poly" means many; "morph" means forms.
  • Languages can interpret the same word or symbol correctly in various ways.

Operator Loading

  • This allows operators to perform tasks differently based on the instance.

Function Overloading

  • Two or more functions have the same name, but different return types or argument numbers.

Method Details

  • It's a program module with statements to carry out a task, which can be called many times.
  • public is an access modifier that allows any class to use it.
  • static indicates a method can be used without object instantiation.
  • void shows that method returns no data.
  • return type describes the data type sent back to calling method.
  • Method Name can be any legal identifier for classes and variables.
  • Parentheses contains sent data to the method.

Method Body

  • It contains implementation and statements that do the work of the method.

Fully Qualified Identifier

  • Contains the complete name that includes the class is.
  • It includes the class name, a dot, and the method name.

Advantages of Creating a Separate Method

  • Makes main() shorter and clearer by using method calls for complex statements.
  • Improves readability with well-named methods that clarify intent.
  • Enhances reusability, allowing methods to be used across applications needing specific actions.

Class Header

  • Has 3 parts: an optional accessor specifier, the keyword class, and a legal identifier, starting with a capital letter.

Java Class Types

  • Those from which objects cannot be instantiated, such as programs with the main() methods.
  • Those from which objects are created.
  • With OOP a class can be created to run as an application to instantiate objects and do both.

Methods

  • Accessor methods or getters retrieve values.
  • Mutator methods or setters (typically prefixed with "set") set/change field values.
  • Data fields are the data components inside a class (declared variables outside any method). static data fields occur once per class vs. non-static ones which happen once per object.

Constructor

  • This is a special method that creates and initializes an object.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Programming Paradigms: POP vs OOP
10 questions
OOP vs FP Comparison Quiz
5 questions
Programming Paradigms and OOP Concepts
42 questions
Use Quizgecko on...
Browser
Browser