{"id":28323634,"url":"https://github.com/night-owl-labs/oop-principles","last_synced_at":"2026-02-24T02:32:09.088Z","repository":{"id":190530505,"uuid":"671287051","full_name":"Night-Owl-Labs/OOP-Principles","owner":"Night-Owl-Labs","description":"🔵 This repository aims to provide a comprehensive guide to Object-Oriented Programming (OOP) principles. Whether you are new to OOP or want to reinforce your understanding, this repository has you covered.","archived":false,"fork":false,"pushed_at":"2025-10-18T00:46:24.000Z","size":1026,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-19T00:46:36.352Z","etag":null,"topics":["oop","oop-principles","oops-in-java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Night-Owl-Labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-07-27T01:35:21.000Z","updated_at":"2025-10-18T00:46:28.000Z","dependencies_parsed_at":"2024-02-16T02:27:29.098Z","dependency_job_id":"b9cb3025-fa6c-4aee-8383-e9a758f17877","html_url":"https://github.com/Night-Owl-Labs/OOP-Principles","commit_stats":null,"previous_names":["night-owl-labs/oop-principles"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Night-Owl-Labs/OOP-Principles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Night-Owl-Labs%2FOOP-Principles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Night-Owl-Labs%2FOOP-Principles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Night-Owl-Labs%2FOOP-Principles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Night-Owl-Labs%2FOOP-Principles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Night-Owl-Labs","download_url":"https://codeload.github.com/Night-Owl-Labs/OOP-Principles/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Night-Owl-Labs%2FOOP-Principles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29769176,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T01:40:24.820Z","status":"online","status_checked_at":"2026-02-24T02:00:07.497Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oop","oop-principles","oops-in-java"],"created_at":"2025-05-25T16:14:35.398Z","updated_at":"2026-02-24T02:32:09.057Z","avatar_url":"https://github.com/Night-Owl-Labs.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- Begin README --\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Night-Owl-Labs/OOP-Principles\" target=\"_blank\"\u003e\n        \u003cimg src=\"./docs/images/icon.png\" width=\"200\" height=\"200\"/\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Night-Owl-Labs\"\u003e\u003cimg src=\"https://img.shields.io/badge/github-follow_us-181717?style=for-the-badge\u0026logo=github\u0026color=181717\" alt=\"GitHub Badge\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://x.com/reciperesizer\"\u003e\u003cimg src=\"https://img.shields.io/badge/email-follow_us-white?style=for-the-badge\u0026logo=x\" alt=\"X Badge\" /\u003e\u003c/a\u003e\n    \u003ca href=\"mailto:support@nightowllabs.io\"\u003e\u003cimg src=\"https://img.shields.io/badge/gmail-contact_us-EA4335?style=for-the-badge\u0026logo=gmail\" alt=\"Email Badge\" /\u003e\u003c/a\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://prgportfolio.com\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/PRG-Silver Project-C0C0C0?style=for-the-badge\u0026logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB3aWR0aD0iMjYuMDAwMDAwcHQiIGhlaWdodD0iMzQuMDAwMDAwcHQiIHZpZXdCb3g9IjAgMCAyNi4wMDAwMDAgMzQuMDAwMDAwIgogcHJlc2VydmVBc3BlY3RSYXRpbz0ieE1pZFlNaWQgbWVldCI+Cgo8ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSgwLjAwMDAwMCwzNC4wMDAwMDApIHNjYWxlKDAuMTAwMDAwLC0wLjEwMDAwMCkiCmZpbGw9IiNDMEMwQzAiIHN0cm9rZT0ibm9uZSI+CjxwYXRoIGQ9Ik0xMiAzMjggYy04IC04IC0xMiAtNTEgLTEyIC0xMzUgMCAtMTA5IDIgLTEyNSAxOSAtMTQwIDQyIC0zOCA0OAotNDIgNTkgLTMxIDcgNyAxNyA2IDMxIC0xIDEzIC03IDIxIC04IDIxIC0yIDAgNiAyOCAxMSA2MyAxMyBsNjIgMyAwIDE1MCAwCjE1MCAtMTE1IDMgYy04MSAyIC0xMTkgLTEgLTEyOCAtMTB6IG0xMDIgLTc0IGMtNiAtMzMgLTUgLTM2IDE3IC0zMiAxOCAyIDIzCjggMjEgMjUgLTMgMjQgMTUgNDAgMzAgMjUgMTQgLTE0IC0xNyAtNTkgLTQ4IC02NiAtMjAgLTUgLTIzIC0xMSAtMTggLTMyIDYKLTIxIDMgLTI1IC0xMSAtMjIgLTE2IDIgLTE4IDEzIC0xOCA2NiAxIDc3IDAgNzIgMTggNzIgMTMgMCAxNSAtNyA5IC0zNnoKbTExNiAtMTY5IGMwIC0yMyAtMyAtMjUgLTQ5IC0yNSAtNDAgMCAtNTAgMyAtNTQgMjAgLTMgMTQgLTE0IDIwIC0zMiAyMCAtMTgKMCAtMjkgLTYgLTMyIC0yMCAtNyAtMjUgLTIzIC0yNiAtMjMgLTIgMCAyOSA4IDMyIDEwMiAzMiA4NyAwIDg4IDAgODggLTI1eiIvPgo8L2c+Cjwvc3ZnPgo=\" alt=\"Silver\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---------------\n\n\u003ch1 align=\"center\"\u003eObject-Oriented Programming (OOP) Principles\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://github.com/Night-Owl-Labs/Software-Principles-Collection\" target=\"_blank\"\u003e\n        \u003cimg src=\"./docs/images/banner_collection.png\" width=\"500\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n**Object-Oriented Programming (OOP)** is a programming paradigm that focuses on objects and data rather than functions and logic. It is based on the concept of objects that contain data and methods that operate on that data. OOP allows us to break down complex problems into smaller, more manageable chunks\n\n---------------\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Four Principles of OOP](#four-principles-of-oop)\n    - [1. Encapsulation](#1-encapsulation)\n    - [2. Abstraction](#2-abstraction)\n    - [3. Inheritance](#3-inheritance)\n    - [4. Polymorphism](#4-polymorphism)\n- [Conclusion](#conclusion)\n- [Resources](#resources)\n- [License](#license)\n- [Credits](#credits)\n\n## Introduction\n\nThis repository provides a brief explanation of the four main principles of **Object-Oriented Programming (OOP)** along with corresponding code examples.\u003cbr\u003e\n\n\u003e [!NOTE]\n\u003e The code examples are written in Java, but the principles can be applied to any object-oriented programming language.\n\n## Four Principles of OOP\n\nThe four main principles of OOP are encapsulation, abstraction, inheritance, and polymorphism. Let's take a closer look at each of them.\n\n### 1. Encapsulation\n\nEncapsulation is the practice of bundling data and methods that operate on that data within a single unit (object). It helps protect the object's internal state from direct manipulation and enforces controlled access through well-defined methods.\n\nExample in Java:\n\n```java\nclass BankAccount {\n    private double balance;\n\n    // Getter method to access the balance (read-only)\n    public double getBalance() {\n        return balance;\n    }\n\n    // Setter method to update the balance (write-only)\n    public void setBalance(double newBalance) {\n        if (newBalance \u003e= 0) {\n            balance = newBalance;\n        }\n    }\n\n    // Method to deposit money into the account\n    public void deposit(double amount) {\n        if (amount \u003e 0) {\n            balance += amount;\n        }\n    }\n\n    // Method to withdraw money from the account\n    public void withdraw(double amount) {\n        if (amount \u003e 0 \u0026\u0026 amount \u003c= balance) {\n            balance -= amount;\n        }\n    }\n}\n```\n\nIn this example, the `balance` data member is encapsulated within the `BankAccount` class. External code cannot directly modify the `balance`, but it can interact with the account through the `deposit` and `withdraw` methods, which ensure controlled access to the balance.\n\n### 2. Abstraction\n\nAbstraction involves simplifying complex reality by creating classes that represent essential characteristics and behaviors while hiding unnecessary details.\n\nExample in Java:\n\n```java\nabstract class Shape {\n    abstract double calculateArea();\n}\n\nclass Circle extends Shape {\n    private double radius;\n\n    public Circle(double radius) {\n        this.radius = radius;\n    }\n\n    @Override\n    double calculateArea() {\n        return Math.PI * radius * radius;\n    }\n}\n\nclass Rectangle extends Shape {\n    private double length;\n    private double width;\n\n    public Rectangle(double length, double width) {\n        this.length = length;\n        this.width = width;\n    }\n\n    @Override\n    double calculateArea() {\n        return length * width;\n    }\n}\n```\n\nHere, the `Shape` class is an abstract class that defines the concept of a shape with an abstract method `calculateArea()`. The `Circle` and `Rectangle` classes are concrete subclasses that extend `Shape` and provide their implementations for the `calculateArea()` method. The details of the shape's type (circle or rectangle) are abstracted away, and we can work with shapes in a more generalized manner.\n\n### 3. Inheritance\n\nInheritance allows a class (subclass) to inherit properties and behaviors from another class (superclass). It promotes code reuse and supports the \"is-a\" relationship.\n\nExample in Java:\n\n```java\nclass Animal {\n    void makeSound() {\n        System.out.println(\"Animal makes a sound\");\n    }\n}\n\nclass Dog extends Animal {\n    @Override\n    void makeSound() {\n        System.out.println(\"Dog barks\");\n    }\n}\n\nclass Cat extends Animal {\n    @Override\n    void makeSound() {\n        System.out.println(\"Cat meows\");\n    }\n}\n```\n\nIn this example, the `Animal` class serves as the superclass, and `Dog` and `Cat` are subclasses. They inherit the `makeSound()` method from the `Animal` class, but each subclass provides its implementation, representing the \"is-a\" relationship between animals and specific types of animals.\n\n### 4. Polymorphism\n\nPolymorphism allows objects to take on multiple forms or methods to have multiple implementations. It enables a unified interface for different classes.\n\nExample in Java:\n\n```java\nclass Printer {\n    void print(String content) {\n        System.out.println(\"Printing: \" + content);\n    }\n}\n\nclass LaserPrinter extends Printer {\n    @Override\n    void print(String content) {\n        System.out.println(\"Laser printing: \" + content);\n    }\n}\n\nclass InkjetPrinter extends Printer {\n    @Override\n    void print(String content) {\n        System.out.println(\"Inkjet printing: \" + content);\n    }\n}\n```\n\nIn this example, the `Printer` class has a `print()` method, and both `LaserPrinter` and `InkjetPrinter` are subclasses of `Printer`. Depending on the object type, the appropriate implementation of the `print()` method is invoked at runtime, achieving polymorphic behavior.\n\n## Conclusion\n\nUnderstanding and applying these four principles of Object-Oriented Programming in Java can lead to more organized, reusable, and maintainable code. Feel free to explore the provided examples and experiment further with OOP concepts. Happy coding!\n\n## Resources\n\n- [Object-Oriented Programming (OOP) Concepts in Java](https://www.geeksforgeeks.org/object-oriented-programming-oops-concept-in-java/)\n- [OOP Concepts in Java](https://www.javatpoint.com/java-oops-concepts)\n\n## License\n\nThis project is released under the terms of the **MIT License**, which permits use, modification, and distribution of the code, subject to the conditions outlined in the license.\n- The [MIT License](https://choosealicense.com/licenses/mit/) provides certain freedoms while preserving rights of attribution to the original creators.\n- For more details, see the [LICENSE](LICENSE) file in this repository. in this repository.\n\n## Credits\n\n**Author:** [Night Owl Labs, LLC.](https://github.com/night-owl-labs) \u003cbr\u003e\n**Email:** [support@nightowllabs.io](mailto:support@nightowllabs.io) \u003cbr\u003e\n**Website:** [nightowllabs.io](https://www.nightowllabs.io) \u003cbr\u003e\n**Reference:** [Main Branch](https://github.com/Night-Owl-Labs/OOP-Principles) \u003cbr\u003e\n\n---------------\n\n\u003cdiv align=\"center\"\u003e\n    \u003ca href=\"https://nightowllabs.io\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/Night-Owl-Labs/.github/main/docs/images/footer.png\" width=\"100\" height=\"100\"/\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n\u003c!-- End README --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnight-owl-labs%2Foop-principles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnight-owl-labs%2Foop-principles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnight-owl-labs%2Foop-principles/lists"}