Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOP Principles #42

Open
sophryu99 opened this issue Nov 17, 2022 · 1 comment
Open

OOP Principles #42

sophryu99 opened this issue Nov 17, 2022 · 1 comment
Labels

Comments

@sophryu99
Copy link
Owner

sophryu99 commented Nov 17, 2022

Object Oriented Programming, OOP

The purpose of OOP:

  • To create understandable, readable, and testable code that many developers can collaboratively work on

Properties of OOP:

1. Abstraction:

  • aims to hide complexity from users and show them only relevant information
  • For an example, when you are driving a car, you don't need to know about the engines and the internal workings.

2. Encapsulation:

  • Helps with data security; allows you to protect the data stored in a class from system-wide access

3. Inheritance:

  • Makes it possible to create a child class that inherits the fields and methods of the parent class
  • The child class can override the values and methods of the parent class; it can also add new data and functionality to its parent
  • Parent class = superclass, base class
  • Child class = subclass, derived class

4. Polymorphism:

  • Refers to the ability to perform a certain action in different ways
  • In Java, there are two forms: method overloading and method overriding
  • Method overloading: happens when various methods with the same name are present in a class. They are differentiated by the number, order, or types of their parameters
  • Method overriding: occurs when a child class overrides a method of its parent

Source

@sophryu99 sophryu99 added the Dev label Nov 17, 2022
@sophryu99 sophryu99 changed the title OOP, SOLID Principles OOP Principles Nov 17, 2022
@sophryu99
Copy link
Owner Author

SOLID Principles

The Single Responsibility Principle
The Open-Closed Principle
The Liskov Substitution Principle
The Interface Segregation Principle
The Dependency Inversion Principle

The Single Responsibility Principle

  • A class should do one thing and therefore it should have only a single reason to change
  • Only one potential change in the software's specification should be able to affect the specification of the class
  • Adv1: When different teams work on the same project and edit the same class for different reasons, this could lead to incompatible modules. SRP prevents this.
  • Adv2: Makes version control easier. Fewer merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant