Object Oriented Programming (OOP) is the foundation of mastering most of the widely used programming languages such as Java, Python, Ruby and, of course, Swift. It helps you in the process of designing your app because an app without any proper planning will make you go crazy (trust me, been there, done that).
OOP may sound rather abstract but it’s very relatable to your everyday life. To illustrate how this logic works, letβs talk about building your own e-commerce app like Lazada. Before you build it, think about what your app is, in a very simple manner, preferably a one-liner.
Lazada is a marketplace where buyers purchase goods from sellers.
Yes, keep the idea as simple as possible. Once you have got it, check out the 4 step-by-step guide below that will give you an overview of how Object Oriented Programming (OOP) works.
Step 1: Understand the term βObjectβ in OOP.
What is βObjectβ?
An object is a noun that refers to things, person and place (I hope this rings a bell). For example, a car is an object.
Once you have figured out what object means, let’s move on to step 2.
Step 2: Identify the objects in the description
Single out all the objects you can find in your description of your app.
Lazada is a marketplace where buyers purchase goods from sellers.
So far so good? That was easy right?
Step 3: Extract the objects out and singularize them
So now we have:
- Marketplace
- Buyer
- Goods/Product
- Seller
In this example, the noun βmarketplaceβ is too generic as it refers to the main idea of the app itself, therefore, it will be excluded. It will also be great to think outside the box (since you want to be a programmer) and imagine what else the app allows buyers and sellers to do. When you use Lazada, I am sure you would always go through the reviews of the products before deciding whether to buy them. There you go, now we have 1 more object identified:-
- Buyer
- Goods/Product
- Seller
- Review
Step 4: Think about the properties and functions of the object
After coming up with a list of objects that you think are essential to your app, you should then ask yourself 2 questions about the object:
- What does the object have? (properties)
- What can the object do? (functions)
β
Let’s look at the following examples:
Both buyer and seller have name, birth date, email address and other personal information about themselves.
Buyer can browse through different products, add them to cart and purchase them. Seller can upload their own products and accept payment from buyer.
Why is this important?
Without knowing properties of the object, you would not be able to have a clear idea of what information your app should store and display. Without knowing functions of the object, you would not be able to write the logic which powers the way your app works.
Let’s look at another example to make sure you understand this concept:
Product has brand name, description, price, quantity available.
Product can be purchased by a buyer (lowering the quantity available).
Congratulations! If you are able to follow these 4 steps, you have understood the most fundamental part of the concept – OOP.But wait, are you sure you really get it?
Challenge for you!
How can you apply the concept of OOP to popular apps such as Uber and Airbnb using the guide above?Let us know by commenting below.
-
Josh Tenghttps://www.nextacademy.com/author/josh/
-
Josh Tenghttps://www.nextacademy.com/author/josh/
-
Josh Tenghttps://www.nextacademy.com/author/josh/
-
Josh Tenghttps://www.nextacademy.com/author/josh/