DEV Community

thandhla
thandhla

Posted on

The Principles of Objects-Oriented Programs(OOP) In Java.

Image description

Object-oriented programming (OOP) is a programming paradigm in which programs are designed using ๐—ฐ๐—น๐—ฎ๐˜€๐˜€๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ผ๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜๐˜€.

A class is a template or blueprint from which objects are made from. Classes define the properties and methods that an object can have, and objects are unique instances of a class.

๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜-๐—ผ๐—ฟ๐—ถ๐—ฒ๐—ป๐˜๐—ฒ๐—ฑ ๐—ฝ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ด ๐—ต๐—ฎ๐˜€ ๐Ÿฐ ๐—บ๐—ฎ๐—ถ๐—ป ๐—ฝ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ๐˜€; ๐—ฒ๐—ป๐—ฐ๐—ฎ๐—ฝ๐˜€๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป, ๐—ถ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ, ๐—ฎ๐—ฏ๐˜€๐˜๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ผ๐—ป, and ๐—ฝ๐—ผ๐—น๐˜†๐—บ๐—ผ๐—ฟ๐—ฝ๐—ต๐—ถ๐˜€๐—บ.

๐—˜๐—ป๐—ฐ๐—ฎ๐—ฝ๐˜€๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป hides internal details but exposes data & methods via a public interface, preventing unintentional changes. E.g. โ€” a player can view a pet's age but can't accidentally change it. But they can run methods avail on the public interface like changing a pet's name.

๐—œ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฎ๐—ป๐—ฐ๐—ฒ allows classes to inherit properties and methods from other classes, making code reusable and organized. E.g. โ€” A "SuperPet" class that extends from "Pet "and would inherit "age", "name", "eat", and "speak"; while defining new behaviors like "fly"

๐—ฃ๐—ผ๐—น๐˜†๐—บ๐—ผ๐—ฟ๐—ฝ๐—ต๐—ถ๐˜€๐—บ is a principle that enables objects to change their form by extending or overriding existing methods. E.g. A "Dog" & "Cat" class that extended from the "Pet", shouldn't share the same "speak" method. You'd override it to have its own logic like "woof" or "meow"

๐—”๐—ฏ๐˜€๐˜๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ผ๐—ป reduces complexity by only surfacing the information needed for a given context or use case. E.g. A โ€œPlayerโ€ class doesnโ€™t need to know how the โ€œeatโ€ method works in the โ€œPetโ€ class, it just needs to know how to interact with it โ€” i.e. its input & output.

Top comments (0)