OOP Concepts

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards
What is OOP?
  • OOP is a way to design software by modeling real-world entities as objects.

  • The software operates as a bunch of objects talking to each other. An object is a collection of data and the methods which operate on that data.

2
New cards
Why OOP? (4)
  • Main advantage: better manageable code.

  • Overall understanding of the software is increased.

  • Easier maintenance due to encapsulation. You can make changes to representations while keeping methods the same.

  • Useful for relatively big software

3
New cards
What are the advantages of OOP? (4)
  • Code reusability

  • Easier to maintain and update

  • Provides better data security by restricting data access and avoiding unnecessary exposure.

  • Fast to implement & easy to redesign → minimizes the complexity of an overall program

4
New cards
What are the disadvantages of OOP? (4)
  • The programmer should have good thinking in terms of objects as everything is treated as an object in OOP

  • Proper planning is required

5
New cards
What is a class?
  • A class is like a building block of OO Programs.

  • It is a user defined data type that contains the data members and member functions that operate on the data.

  • It is like a blueprint of of objects having common properties and methods

6
New cards
What is an Object?
  • An object is an instance of a class.

  • Data members & methods of a class cannot be used directly.

  • We need to create an object (or instance) of the class to use them.

  • They are the actual entities that have a state and behavior.

7
New cards
What are the main features of OOP? (4)
  • Encapsulation

  • Data Abstraction

  • Polymorphism

  • Inheritance

8
New cards
What is Encapsulation?
  • The binding of data and methods that manipulate them into a single unit such that sensitive data is hidden from the users.

  • Data Hiding: Restricts access to members of an object.

  • Bundling of data and methods: the data members and methods that operate on an object are wrapped into a single unit known as a class.

9
New cards
What is Abstraction?

The principle of hiding complex implementation details and showing only the essential features or functionality to the user, focusing on what an object does rather than how it does it

10
New cards
What are Abstract Classes?
  • A class you cannot instantiate/cant create objects of this class.

  • Enforces and organizes exactly what every subclass of the abstract class MUST have.

  • You can however make subclasses of an abstract class that CAN be instantiated

    • Ex) public class Cat extends Animal: it makes sense to be able to instantiate a Cat object. But it doesn't make sense to instantiate an Animal object bc what kind of animal would it be? Therefore it would make sense to make the Parent Animal class an abstract class.

11
New cards
What are Abstract Methods?
  • Abstract classes can contain abstract methods or can have regular methods too (these however do not NEED to be implemented in the subclasses)

  • Abstract method means the method has no body.

    • Ex) in the abstract animal class we have the abstract method makeNoise(). We don't want a body because every animal makes different noises. So now the child class must implement the abstract method using @Override and provide the body.

12
New cards
What is an Interface? (implements)
  • In an interface, all methods are assumed to be abstract.

  • You cannot instantiate objects using an interface

  • If a class implements an Interface, it must implement all of its methods using Override

13
New cards

Difference Between Abstract Class and interface (3)

  • Abstract classes can have abstract and non-abstract methods. In an interface, all methods are assumed to be abstract.

  • You can implement as many interfaces as you want but a class can only extend one abstract class. (You can extend a class and implement interfaces).

  • In interfaces, any declared fields are static and final. So they must be instantiated and can't be changed. So these will be applied to every class that implements the interface. (doesn't really make sense, which is why we have abstract classes). Abstract classes can have final, non-final, static and non-static variables.

14
New cards

When to create Abstract class vs Interface?

  • Create abstract class if you have a lot of closely related classes that you want to have the same functionality and same type of fields available

  • Create an interface if you have a lot of unrelated classes that you all want to do a certain thing. That makes it so that you can guarantee other types of classes will be able to “Poop” even if they aren't “animals”

15
New cards
What is Inheritance?
A class is derived from another class and uses data and implementation of that other class. Parent → child, superclass → subclass
16
New cards
What is Polymorphism?
  • It is the property of some code to behave differently for different contexts.

  • For example, defining multiple functions having the same name but working differently.

  • There are 2 types of polymorphism

    • Compile-Time Polymorphism

      • AKA static polymorphism or early binding

      • The binding of the call to its code is done at compile time.

      • Method overloading or operator overloading are examples of compile-time polymorphism

    • Runtime Polymorphism

      • AKA dynamic polymorphism or late binding

      • The actual implementation of the function is determined during runtime/execution.

      • Function overriding is an example of this method.

17
New cards
What are access specifiers?
  • Keywords that are used to specify or control the accessibility of entities like classes or methods.

  • Public, private, and protected are examples

18
New cards
Overloading VS Overriding
  • Overloading → compile time polymorphism: allows an entity to have numerous implementation of the same name

  • Overriding → runtime polymorphism: an entity with the same name but a different implementation is executed.

19
New cards
Types of Interitance (5)
  • Single Inheritance: Child class derived directly from the base class

  • Multiple Inheritance (not supported in Java): Child class derived from multiple base classes

  • Multilevel Inheritance: Child class derived from a class which was also derived from a different base class

  • Hierarchical Inheritance: Multiple child classes derived from a single base class

  • Hybrid inheritance: Inheritance consisting of multiple inheritance types

20
New cards
What is a constructor?
  • A block of code that initializes a newly created object

  • Resembles an instance method but is not a method because it does not have a return type

  • Constructors can be overloaded in Java when we want constructors with different parameters.

21
New cards
Types of constructors (4)
  • Default Constructor: does not take any arguments. Automatically defined by the compiler when no constructor definition is provided

  • Non-parameterized Constructor: user-defined constructor with no args or parameters

  • Parameterized Constructor: A constructor that takes some args

  • Copy Constructor: initializes an object using another object of the same class.