Blueprints for building (OOP)

Object Oriented Programming has been around for a while. When I began my career, I programmed using procedural methods until I learned about OOP. What is OOP really? When I began learning about OOP, it took me a bit to catch on to the concept. I found it to be somewhat of a large topic that at first was muddy. There are a lot of OOP principles to learn…more than can be explored within one blog post. I will periodically explore various OOP principles and you will find them scattered throughout my code projects.

When I began programming with OOP principles, one of the first items I had to learn was what classes and objects are and how they work together.

First…the definitions…

Class – a set of functions that work together to accomplish a task. It can contain or manipulate data, but it usually does so according to a pattern rather than a specific implementation. An instance of a class is considered an object.

Object – receives all of the characteristics of a class, including all of its default data and any actions that can be performed by its functions. The object is for use with specific data or to accomplish particular tasks. To make a distinction between classes and objects, it might help to think of a class as the ability to do something and the object as the execution of that ability in a distinct setting.

Here is another way of thinking about it…

Let’s say you were going to build a brand new subdivision where all the houses look alike. You create the blueprints and build your first house. You then re-create the blueprints and build a second house that looks exactly like the first one. You then repeat this process throughout the subdivision. This would not be a very wise way to build your subdivision. Why re-create the blueprints if the houses are all alike? It is a waste. Instead, you would use the first set of blueprints to build all of the houses within the subdivision.

Classes = Blueprints

Objects = Houses

So you create the class once and then can build a lot of objects from that class. Here is an example in Java…

[code lang=”java”]
// This is my class
public class House{
public House(String name){
// This constructor has one parameter, type.
System.out.println("Passed Type is :" + type);
}
public static void main(String []args){
// Following statement would create an object myHouse
House myHouse = new House( "ranch" );
}
}
[/code]

Happy Coding!

Clay Hess

More To Explore

Code

The Contact Picker API: Fast, private access to a user’s address book

The Contact Picker API lets mobile web apps open the native contacts chooser so users can share exactly the fields you request—like name, phone, email, address, or avatar—without granting blanket access to their entire address book. It’s user-initiated, privacy-preserving, and perfect for speeding up invites and form fills.

Focused software developer debugging code on multiple screens in dark environment
Code

Mastering the Console API: A Developer’s Best Debugging Friend

Ever find yourself relying solely on console.log() for debugging? You’re missing out on the Console API’s full potential. This powerful debugging toolkit offers specialized methods for timing operations, inspecting complex objects, tracing function calls, and organizing your debugging output. In just minutes, you can elevate your troubleshooting skills from basic to professional-grade. Let’s explore how the Console API can transform your development workflow and help you solve bugs more efficiently than ever before.

Share This Post

small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.