OOP Concepts

Object

An object:

  • stores its state in fields (or variables)
  • exposes its behavior through methods (or functions)

Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

Hiding internal state and requiring all interaction to be performed through an object's methods is known as data encapsulation — a fundamental principle of object-oriented programming.

By attributing state and providing methods for changing that state, the object remains in control of how the outside world is allowed to use it.

Bundling code into individual software objects provides a number of benefits, including:

  1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
  2. Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.
  3. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.
  4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

Class

A class is the blueprint from which individual objects are created.

Inheritance

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

Interface

In its most common form, an interface is a group of related methods with empty bodies.

Package

A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer.

https://docs.oracle.com/javase/tutorial/java/concepts/index.html

Last updated on