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

E-commerce: An introduction

E-commerce: An introduction

Note: Much of the information in this blog post comes from Google’s online Digital Marketing and E-commerce course on Coursera. Introduction E-commerce is the buying and selling of goods or services using the internet. In other words, e-commerce involves a store that...

Digital Marketing terminology(part 6)

Digital Marketing terminology(part 6)

Digital Marketing Terminology(part 6) Note: These terms are from the Google Digital Marketing & E-commerce course 6: Make the Sale: Build, Launch, and Manage E-commerce Stores A Abandoned cart email: A follow-up email sent to customers who added an item to their...

Digital Marketing terminology(part 5)

Digital Marketing terminology(part 5)

Digital Marketing Terminology Note: These terms are from the Google Digital Marketing & E-commerce course part 5: Assess for Success: Marketing Analytics and Measurement A A/B testing: A method of testing where two versions of content with a single differing...

Call Now Button