OOP Concepts: Encapsulation, Inheritance, Polymorphism - PDF

Summary

This document covers fundamental concepts of Object-Oriented Programming (OOP), including encapsulation, inheritance, and polymorphism. It explains these OOP principles and discusses the advantages and disadvantages of OOP design and coding. The document uses examples to illustrate the concepts.

Full Transcript

FEATURES OF OOP 2.1 Encapsula;on – inclusion of both data and ac;ons into a single component Classes contain data and ac;ons that are built.in such a way so that their structure is hidden and can only be accessed outside the class via specific methods 2.2 Inh...

FEATURES OF OOP 2.1 Encapsula;on – inclusion of both data and ac;ons into a single component Classes contain data and ac;ons that are built.in such a way so that their structure is hidden and can only be accessed outside the class via specific methods 2.2 Inheritance (1.3,1.4,1.6) – refers to that one object (child/subclass) is a specialized form of another object (parent/superclass) 2.3 Polymorphism - means “many“ – the ability to have many forms Int: add(int a, int b) – takes in two integer parameters, a and b, and adds them together and returns the results as an integer Int: add(int a, int b, int c) – takes three integers, adds them together, and returns the result as an integer Float: add(float a float b) – takes in two float numbers and adds them together, and returns the result as a float STATIC POLYMORPHOSIS – the compiler is able to understand the method signatures and decide the method that needs to be invoked for a par;cular method call depending on the number and types of parameters passed DYNAMIC POLYMORPHOSIS – when a subclass overrides ac;ons of the superclass - Allows for subclasses to alter any parent class ac;ons and make them specific to their needs 2.4 Plays the role of a protec;ve wall that prevents data and ac;ons from being accessed from outside a class, resul;ng in unwanted behavior Data and ac;ons are only accessible in specific predefined ways ADVANTAGES OF ENCAPSULATIONS: - Data in a class can be made read or write only - A class restricts the ways that its data and ac;ons can be altered or called - A class can hide the way that data is stored - Easier to maintain, as changes to data and ac;ons in a class can take place without being apparent on the outside, as long as data and ac;ons can s;ll be accessed in the same way - Increase in usability Encapsula;on creates a “black box“ for an object, separa;ng its behavior and implementa;on by restric;ng access to data and ac;ons as necessary Outside the object, only the behavior of the object is apparent, hiding and protec;ng its internal workings 2.5 ADVANTAGES OF INHERITANCE: 2.6 ADVANTAGES OF POLYMORPHOSIS: 2.7 Libraries of objects – a collec;on of classes that have already been wri\en in code and can be used by the programmer while developing a program The availability of libraries simplifies the work that has to be put into a project, since standard, tested, working code is available for various func;ons – used as a “black box“ Allows reuse of code 2.8 DISADVANTAGES OF OOP: - For small projects, with few developers and modules, OOP may increase complexity, development ;me, and maintenance cost - Programming in OOP requires care in order not to make the project too abstract, which would lead to unnecessarily large and complex programs 2.9 Working as a solo developer allows for one person to be in charge of the whole development cycle from design to implementa;on, tes;ng, and maintenance - This approach is reasonable for small-scale projects and in fact does have some advantages, since the developer is aware of every aspect of the project - Allows the developers to have an overall view of the whole project and be able to make changes quickly and without the need to communicate with anyone else These decisions are quicker for a single individual than for a team that has to coordinate Solo developers do not need to develop a common “language“ with his/her peers, since he/she is working alone, and will not face any of the coordina;on or collabora;on problems that may arise in a team

Use Quizgecko on...
Browser
Browser