D.2 - Features of OOP

studied byStudied by 1 person
0.0(0)
Get a hint
Hint

Encapsulation

1 / 20

21 Terms

1

Encapsulation

  • Encapsulation is the technique of making the states in a class private and providing access to those states via public behaviors (methods).

  • Data and actions are limited to the object in which they are created.

    • It is a form of data hiding. If a state is declared private it cannot be accessed by any method outside the class.

New cards
2

Inheritance

  • A process whereby one object inherits the properties of another object (called super / sub or parent / child classes).

  • This is called an “is-a” relationship.

  • In java you can only inherit from one class at a time.

New cards
3

Keyword Inheritance

  • The keyword used is extends.

  • In programming inheritance is implemented by using the keyword extends in the subclass to connect it to its super class.

New cards
4

Polymorphism

  • It means that two methods can have the same name but different contents / functions.

    • Methods have the same name but different parameter lists and processes.

New cards
5

Types of Polymorphism

  • Overloading

  • Overriding

New cards
6

Overloading

  • The same class

  • Allows different methods to have the same name, but different signatures where signature can differ by the number of input parameters or type of input parameters or both.

New cards
7

Overriding

  • Different classes / inheritance

  • Allows a subclass to provide a specific implementation of a method that is already provided by one of its super classes.

  • When a method in a subclass has the same name, same parameters, or signature, and same return type as a method in its super-class then the method in the subclass overrides the method in the superclass.

New cards
8

Overloading versus Overriding

  • Overloading is about the same function having different signatures (usually in the same class).

  • Overriding is about the same function, same signature, but different classes connected through inheritance.

New cards
9

Advantages of Encapsulation

  • Data hiding

  • Reusability

  • Testing code ease

  • Increased flexibility

New cards
10

Data Hiding

  • The user will have no idea about the inner implementation of the class (implies security)

  • It will not be visible to the user how the class is storing values in the variables.

  • They only know that we are passing the values to a setter method and variables are getting initialized with that value.

New cards
11

Reusability (Encapsulation)

  • Encapsulation also improves the reusability of the code (write once / use many times)

  • Methods can be copied to different / new classes and help meet new requirements.

New cards
12

Ease of testing code (Encapsulation)

  • Encapsulated code is easy to test with unit testing (a type of automated testing that tests many different types of data quickly)

  • It is easier to fix larger problems if you know which method is returning the wrong response.

New cards
13

Increased Flexibility (Encapsulation)

  • We can make the variables of the class as read-only or write-only depending on our requirement

  • If we wish to make the variables as read-only then we can omit the setter methods

  • Or if we wish to make the variables as write-only then we have to omit the get methods.

New cards
14

Advantages of Inheritance

  • Minimizes the amount of duplicate code

    • Common code becomes the superclass

  • Organizes code better

    • Using a superclass has better abstraction

  • Makes code more flexible to change

    • Can make application code more flexible to change as classes that inherit from a common super class can be used interchangeably.

  • a parent object holds common data and actions, which enhances reuse and reduces maintenance overheads

New cards
15

Advantages of Polymorphism

  • Overriding

    • It allows a general class to specify methods that will be common to all of its derivatives while allowing sub classes to define the specific implementation of some or all of those methods.

    • One interface, multiple methods - overridden methods

    • Allow you to call methods of any of the derived classes without even knowing the type of derived class object.

  • Overloading

    • Do not need different names for functions doing the same thing

New cards
16

Advantages of Libraries of Objects

  • Time saving:

    • Sorting algorithms do not have to be re-invented

    • Complex algorithms and processes can be reused

New cards
17

Libraries of Objects

  • JUnit (64% of top Java projects)

    • Testing framework for java programs

  • SLF4J 22%

    • Allow the end-user to plug-in the desired logging system

  • Log4j 16.76%

    • A tool to help the programmer output log statements to a variety of output targets

  • Google Guava 15.6%

    • Common libraries for Java, mainly developed by Google engineers.

  • Apache-commons 12.63%

    • Commons proper is dedicated to one goal: create and maintain reusable Java components.

New cards
18

Disadvantages of OOP

  • Increased complexity of small problems

    • OOP typically involves more lines of code than procedural programs.

    • OOP are typically slower than procedure-based programs, as they typically require more instructions to be executed.

  • Unsuited to particular classes of problems

    • Programs may lend themselves well to functional-programming style, logic-programming style, or procedural-based programming, and using object oriented will not create efficient programs.

    • Problems that tend to be small and involve only one data source.

New cards
19

Programming Teams Advantages

  • Speed of completion (concurrent working)

  • Information hiding to reduce module dependencies

    • Developers only need to know the name and required parameters to use a behavior, they can use code without needing to understand how it functions

    • Security benefit as coders do not have access to the actual data themselves

  • Expertise in a narrow field

    • Assembling a complex project requires many different skills.

    • By allowing each part of the program to be programmed by an expert in that field, the quality of the final product is higher than one by a jack of all trades.

New cards
20

Programming Teams Disadvantage

You need a common language to resolve problems

New cards
21

Advantages of Modularity

  • Easier debugging and testing

    • By having smaller modules to test, it is easier to find and fix bugs

    • The number of tests that have to be run to confirm a module is fully operational is reduced according to the number of functions in a particular module.

  • Speedier completion

    • By breaking the project into smaller modules, you could save time by finding modules that already exist in libraries that do the function you are looking for

    • By splitting the task into different modules, each module can be worked on concurrently (except for particular circumstances) thus leading to a speedier completion of the overall project

  • Code blocks are reusable

    • Some problems / functions are very common and possibly occur in multiple different programs (for example the need to make a text box or a clickable button to start a task)

    • By resusing blocks of code, the development time is slashed and the project is completed sooner.

New cards

Explore top notes

note Note
studied byStudied by 12 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 66 people
Updated ... ago
4.2 Stars(5)
note Note
studied byStudied by 15 people
Updated ... ago
4.0 Stars(1)
note Note
studied byStudied by 19 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 44 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 11 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 66 people
Updated ... ago
4.8 Stars(4)
note Note
studied byStudied by 260 people
Updated ... ago
4.5 Stars(4)

Explore top flashcards

flashcards Flashcard24 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard44 terms
studied byStudied by 3 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard59 terms
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard28 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard46 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard39 terms
studied byStudied by 21 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard32 terms
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard23 terms
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)