OOP

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Imperative Programming Paradigm

Imperative programming focuses on HOW to execute program logic and defines control flow as statements that change a program state. This can be further classified as: a) Procedural Programming Paradigm: Procedural programming specifies the steps a program must take to reach the desired state, usually read in order from top to bottom. b) Object-Oriented Programming or OOP: Object-oriented programming (OOP) organizes programs as objects, that contain some data and have some behavior. c) Parallel Programming: Parallel programming paradigm breaks a task into subtasks and focuses on executing them simultaneously at the same time.

Encapsulation

Keeping details (like data and procedures) together in one part of a program so that programmers working on other parts of the program don't need to know about them.

Overloading vs Overriding

Methods in the same class which have the same name but have different parameters. Parameters may be of a different type and/or the number of parameters may be different VS Methods, one in a parent class and the other in a child class which have the same name and parameters. The method in the child class is invoked rather than the parent class method.

Is it always necessary to create objects from class?

No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don't need to be created. You can call the class method directly in this case, using the class name.

Struct

Not the same as class. Not much abstraction can be achieved and is saved in the stack instead of the heap.

What are some advantages of using OOPs?

OOPs is very helpful in solving very complex level of problems. Highly complex programs can be created, handled, and maintained easily using object-oriented programming. OOPs, promote code reuse, thereby reducing redundancy. OOPs also helps to hide the unnecessary details with the help of Data Abstraction. OOPs, are based on a bottom-up approach, unlike the Structural programming paradigm, which uses a top-down approach. Polymorphism offers a lot of flexibility in OOPs.

What are the main features of OOPs?

OOPs or Object Oriented Programming mainly comprises of the below four features, and make sure you don't miss any of these: - Inheritance - Encapsulation - Polymorphism - Data Abstraction

Why is OOPs so popular?

OOPs programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs - Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular

What is meant by the term OOPs?

OOPs refers to Object-Oriented Programming. It is the programming paradigm that is defined using objects. Objects can be considered as real-world instances of entities like class, that have some characteristics and behaviors.

What is encapsulation?

One can visualize Encapsulation as the method of putting everything that is required to do the job, inside a capsule and presenting that capsule to the user. What it means is that by Encapsulation, all the necessary data and methods are bind together and all the unnecessary details are hidden to the normal user. So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.

Interface

Only the declaration of methods is allowed inside an interface. To use an interface, you cannot create objects. Instead, you need to implement that interface and define the methods for their implementation.

function overloading

Process of creating several functions with the same name but different formal parameter lists. void add(int& a, int& b);void add(double& a, double& b);void add(struct bob& a, struct bob& b);

What are some other programming paradigms other than OOPs?

Programming paradigms refers to the method of classification of programming languages based on their features. There are mainly two types of Programming Paradigms: Imperative Programming Paradigm Declarative Programming Paradigm Now, these paradigms can be further classified based:

garbage collection

Releases memory that was used for a variable's value once the variable is no longer to be used by a program.

Data Abstraction

Representing or storing information with methods that separate layers of concerns so that the programmer can work with information while ignoring lower-level details about how the information is represented.

Runtime Polymorphism:

Runtime polymorphism, also known as Dynamic Polymorphism, refers to the type of Polymorphism that happens at the run time. What it means is it can't be decided by the compiler. Therefore what shape or value has to be taken depends upon the execution. Hence the name Runtime Polymorphism.

Types of inheritance

Single Multiple Multi-level Hierarchical Hybrid

What is meant by Structured Programming?

Structured Programming refers to the method of programming which consists of a completely structured control flow. Here structure refers to a block, which contains a set of rules, and has a definitive control flow, such as (if/then/else), (while and for), block structures, and subroutines. Nearly all programming paradigms include Structured programming, including the OOPs model.

Subclass

The child class that extends the superclass and inherits its behavior

access specifier

The keywords public, private, and protected, which determine how an identifier can be used.

3. What are some major Object Oriented Programming languages?

The programming languages that use and follow the Object-Oriented Programming paradigm or OOPs, are known as Object-Oriented Programming languages. Some of the major Object-Oriented Programming languages include: Java C++ Javascript Python PHP And many more.

dynamic polymorphism

The response to a function is determined at run time.

What is meant by Inheritance?

The term "inheritance" means "receiving some quality or behavior from a parent to an offspring." In object-oriented programming, inheritance is the mechanism by which an object or class (referred to as a child) is created using the definition of another object or class (referred to as a parent). Inheritance not only helps to keep the implementation simpler but also helps to facilitate code reuse.

2. What is the need for OOPs?

There are many reasons why OOPs is mostly preferred, but the most important among them are: OOPs helps users to understand the software easily, although they don't know the actual implementation. With OOPs, the readability, understandability, and maintainability of the code increase multifold. Even very big software can be easily written and managed easily using OOPs.

Limitations of Inheritance

Tightly coupled between base class and child class, complexity in code structure when multiple classes are linked via inheritance.

Exception Handling

When there's an error, the program makes an error object and passes it off to the runtime system, which looks for a method in the call stack to handle it.

abstract class

a class that only exists in a model so subclasses can inherit from it

friend function

a special function in C++ which in-spite of not being member function of a class has privilege to access private and protected data of a class.

exception

considered as a special event, which is raised during the execution of a program at runtime, that brings the execution to a halt. The reason for the exception is mainly due to a position in the program, where the user wants to do something for which the program is not specified, like undesirable input.

virtual function

member function of a class, and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.

What is Polymorphism?

refers to something that has many shapes. code data method or objects behave differently under different circumstances or contexts. Compile-time polymorphism and run time polymorphism are the two types of polys in oops

Abstraction

the method of hiding unnecessary details from the necessary ones. It is one of the main features of OOPs. For example, consider a car. You only need to know how to run a car, and not how the wires are connected inside it. This is obtained using Abstraction.

static polymorphism

the response to a function is determined at the compile time.

Superclass

the superior or more general class in a generalization/specialization relationship

Copy Constructor

will clone an object and its values, into another object, provided that both the objects are of the same class

What is a class?

A class can be understood as a template or a blueprint, which contains some values, known as member data or member, and some set of rules, known as behaviors or functions. So when an object is created, it automatically takes the data and functions that are defined in the class.Therefore the class is basically a template or blueprint for objects. Also one can create as many objects as they want based on a class

Constructor

A method for creating an object in a class.

Destructor

A special class member that cleans up when an object is deleted

Abstract Class vs Interface

An abstract class is a class that is not implemented directly, containing one or more abstract methods, or methods that are not yet implemented. An interface can have only abstract methods, with a caveat in default methods. They are not close enough entities to classes to be thought of as one-- they exist primarily to describe a set of functions that a class that is said to be of that interface should have. (cars should accelerate, brake, and change gears, but you would never say that a car is a child of brakes). An important feature of interfaces is that multiple can be implemented by a class, as opposed to the option of extending a single abstract class.

What is an object?

An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior.

How does C++ support Polymorphism?

C++ is an Object-oriented programming language and it supports Polymorphism as well: Compile Time Polymorphism: C++ supports compile-time polymorphism with the help of features like templates, function overloading, and default arguments. Runtime Polymorphism: C++ supports Runtime polymorphism with the help of features like virtual functions. Virtual functions take the shape of the functions based on the type of object in reference and are resolved at runtime.

Classes and memory

Classes do not consume memory until they are initialized as objects.

compile-time polymorphism

Compile time polymorphism, also known as Static Polymorphism, refers to the type of Polymorphism that happens at compile time. What it means is that the compiler decides what shape or value has to be taken by the entity in the picture.

Declarative Programming Paradigm:

Declarative programming focuses on WHAT to execute and defines program logic, but not a detailed control flow. Declarative paradigm can be further classified into: a) Logical Programming Paradigm: Logical programming paradigm is based on formal logic, which refers to a set of sentences expressing facts and rules about how to solve a problem b) Functional Programming Paradigm: Functional programming is a programming paradigm where programs are constructed by applying and composing functions. c) Database Programming Paradigm: Database programming model is used to manage data and information structured as fields, records, and files.

Data Binding

Encapsulation is the proccess of binding data members and the methods together as a whole

Data hiding

Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object

function overriding

If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding.

Example Inheritance

Inheritance is one of the major features of object-oriented programming, by which an entity inherits some characteristics and behaviors of some other entity and makes them their own. Inheritance helps to improve and facilitate code reuse. Let's take three different vehicles - a car, truck, or bus. These three are entirely different from one another with their own specific characteristics and behavior. But. in all three, you will find some common elements, like steering wheel, accelerator, clutch, brakes, etc. Though these elements are used in different vehicles, still they have their own features which are common among all vehicles. This is achieved with inheritance. The car, the truck, and the bus have all inherited the features like steering wheel, accelerator, clutch, brakes, etc, and used them as their own. Due to this, they did not have to create these components from scratch, thereby facilitating code reuse.


Set pelajaran terkait

IB 200 UW Madison Final Exam Review - Sachin Tuli

View Set

ECO 1311 Chapter 9 International Trade

View Set

AP Environmental Science: The Atmosphere

View Set

Ch.6: Cash, Fraud, & Internal Controls

View Set

Day 26: What can we learn from the fossil record?

View Set

Strategic Management Chapter 2 - UNG

View Set