Unit 3 Web Computing
Unit 3 Web Computing
Unit 3 Web Computing
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.
Points to Remember
o Everything is an object
o The class contains the attribute and behavior associated with an object.
Pillars of OOPs
The major concepts that we have discussed above are known as pillars of
OOPs. There are four pillars on which OOP rests.
o Abstraction
o Encapsulation
o Inheritance
o Polymorphism
Abstraction
The concept allows us to hide the implementation from the user but shows
only essential information to the user. Using the concept developer can
easily make changes and added over time.
o It reduces complexity.
o It avoids delicacy.
Encapsulation
Encapsulation is a mechanism that allows us to bind data and functions of
a class into an entity. It protects data and functions from outside
interference and misuse. Therefore, it also provides security. A class is the
best example of encapsulation.
Inheritance
The concept allows us to inherit or acquire the properties of an existing
class (parent class) into a newly created class (child class). It is known
as inheritance. It provides code reusability.
Polymorphism
The word polymorphism is derived from the two words
i.e. ploy and morphs. Poly means many and morphs means forms. It
allows us to create methods with the same name but different method
signatures. It allows the developer to create clean, sensible, readable, and
resilient code.
Class:
For Example: Consider the Class of Cars. There may be many cars with
different names and brands but all of them will share some common properties
like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here,
Car is the class, and wheels, speed limits, mileage are their properties.
2. Object:
For example “Dog” is a real-life Object, which has some characteristics like
color, Breed, Bark, Sleep, and Eats.
Visibility is a big part of OOP. It allows you to control where your class members can be
accessed from, for instance to prevent a certain variable to be modified from outside the
class. The default visibility is public, which means that the class members can be
accessed from anywhere. This means that declaring the visibility is optional, since it will
just fall back to public if there is no access modifier. For backwards compatibility, the old
way of declaring a class variable, where you would prefix the variable name with the
"var" keyword (this is from PHP 4 and should not be used anymore) will also default to
public visibility.
PHP is pretty simple in this area, because it comes with only 3 different access modifiers:
private, protected and public.
Private members can only be accessed from inside the class itself.
Protected members can only be accessed from inside the class it self and its child
classes.
Public members can be accessed from anywhere - outside the class, inside the class it
self and from child classes.
What is a Constructor?
A single class may have multiple constructors that are differentiated based on the
number and type of arguments passed. There are three main types of
constructors, namely, default constructor, parameterized constructor, and copy
constructor.
What is a Destructor?
A destructor does not have any argument and is always called in the reverse
order of the constructor. Destructor are required for destroying the objects to
release the memory allocated to them.
A. Inheritance is the concept in OOPs in which one class inherits the attributes
and methods of another class. The class whose properties and methods are
inherited is known as the Parent class. And the class that inherits the
properties from the parent class is the Child class.
An interface is a contract between itself and any class that implements it.
Interface can have methods, properties, or events. It contains only
declaration of its members and implementation of its members will be
given by the class who implements the interface. Interface makes it easy
to maintain the program. Following are the specified terms of interface.
• In object-oriented computer programming (OOP) languages, the notion of encapsulation (or OOP
Encapsulation) refers to the bundling of data, along with the methods that operate on that data, into
a single unit.
• Containers are just one example of encapsulation in coding where data and methods are bundled
together into a single package.
• A key benefits to hiding information about attributes and methods using encapsulation in
programming is that it prevents other developers from writing scripts or APIs that use your code.
• Sumo Logic complements your existing cyber security measure with cutting-edge threat detection
and security analytics powered by artificial intelligence.
• Hiding data: Users will have no idea how classes are being implemented or stored. All
that users will know is that values are being passed and initialized.
• More flexibility: Enables you to set variables as red or write-only. Examples include:
setName(), setAge() or to set variables as write-only then you only need to omit the get
methods like getName(), getAge() etc.
• Easy to reuse: With encapsulation, it's easy to change and adapt to new requirements.