Consider you are working as a developer in a software house “XYZ” and you have to develop a program that will detect the Real time objects by using the Camera. As a developer, you have to decide which programming paradigm would be feasible to design develop this system.
Identify the programming paradigm from the list given below and justify your answer with proper reasons.
Object Oriented Programming Paradigm
Procedural Programming Paradigm
Object Oriented Programming Paradigm
Because we need to work with objects, and the easiest way to work with them is with Object Oriented Programming. The main advantage of Object Oriented Programming over Procedural Programming is the understanding of the program code itself. Programs written using Procedural Programming become less and less readable with each new version. A program using Object Oriented Programming is better organized because it makes it clear which object is being processed by what.
This is how the program would look like with Procedural Programming:
void Detect(bool ObjDet)
{
if (ObjDet == true)
{
cout << "Object detected!" << endl;
}
else
{
cout << "Object not found." << endl;
}
}
bool ObjectDetection()
{
return true;
}
int main()
{
bool IsObjectDetected = ObjectDetection();
Detect(IsObjectDetected);
}
And this is how the program would look like using object oriented programming:
class Camera
{
public:
void Detect()
{
bool IsObjectDetected = ObjectDetection();
if (IsObjectDetected == true)
{
cout << "Object detected!" << endl;
}
else
{
cout << "Object not found." << endl;
}
}
private:
bool ObjectDetection()
{
return true;
}
};
int main()
{
Camera cam;
cam.Detect();
}
On the one hand, there are no differences between them, on the other hand, in the OOP code, we clearly describe the object and its functions, thereby making it more understandable, and if I want to release a new version for the camera software, then I will not have any problems, then how in code with Procedural Programming with each new version it will be more and more difficult for me to perceive this code.
Comments
Leave a comment