Object-Oriented Programming

March 24, 2023

Objected-oriented programming is a complicated topic that whole textbooks can be written about. Object-oriented programming has simplified coding to a significant degree and is now essentially a staple of modern computer programming. In short, object-oriented programming allows objects, which in Java are represented using classes, to be easily used by other classes and other packages. Packages are generally collections of classes, interfaces, enums, and records that perform particular functions using code. A package can be used by other programs and extended to meet the design needs of the application. Usually, this is done by importing the package as a module to be used by the application.

For example, say we have a class

public class Person {

private int age;

private String name;

private String description;

// The constructor

public Person(int age, String name, String description) {

this.age = age;

this.name = name;

this.description = description;

}

// The getter functions

public int getAge() {

return age;

}

public String getName() {

return name;

}

public String description() {

return description;

}

}

Notice in the above class there are private class variables but public getters. This is generally the convention in creating classes to be used by other applications.

Another Java application can then import this class for its own use generally by typing something like using packageName.className at the top of the application.

Another application might extend this class to improve the functionality of the class or to meet the design needs of their application.

An  example might be:

public class policeOfficer extends packageName.Person {

int age;

String name;

String description;

public policeOfficer(int age, String name, String description) {

super(age, name, description); // Super here calls the superclass that is being extended. In this case the Person class above.

}

public void eatDonuts() {

// Of course there would be a function like this.

System.out.println(“Officer ” + name + ” is currently eating donuts.”);

}

public void arrestPerson() {

// Of course there would be a function like this.

System.out.println(“Officer ” + name + ” is arresting someone.”);

}

// The above function didn’t exist in the original Person class above.

}

Object-oriented programming is a very complex area of computer science. For more information about Object-oriented programming or other computer science or computer programming topics, I recommend this website page here. I also recommend the book Head First Design Patterns: Building Extensible & Maintainable Object-Oriented Software by Eric Freeman and Elisabeth Robson with Kathy Sierra and Bert Bates.

To view more blog posts from our company visit our blog section here.

Related Posts

What is a Website?

What is a Website?

In today's digital age, a website plays a crucial role in establishing an online presence for individuals, businesses, and organizations. It serves as a platform to share information, promote products or services, connect with an audience, and facilitate various...

What is Mixed Reality: Exploring the Future of Technology

What is Mixed Reality: Exploring the Future of Technology

Introduction In a world where technology continues to evolve at an astonishing pace, the line between the virtual and real world is becoming increasingly blurred. What was once only imaginable in the realm of science fiction is now becoming a breathtaking reality....

The Languages of the Web: HTML, CSS, and JavaScript

The Languages of the Web: HTML, CSS, and JavaScript

In the world of web development, three languages reign supreme: HTML, CSS, and JavaScript. These languages are the building blocks of the web, allowing developers to create dynamic and interactive websites. In this article, we will explore the basics of HTML, CSS, and...

Call Now Button