Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,158,277 members, 7,836,244 topics. Date: Wednesday, 22 May 2024 at 12:25 AM

OOP Is Causing Some Problems, I Need Help - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / OOP Is Causing Some Problems, I Need Help (846 Views)

Object Oriented Programming (OOP) Tutorial / Learning Programming? The Common Misconception About Oop / Learn Object Oriented Programming (OOP) AT SANDCROFT SOFTWARE (2) (3) (4)

(1) (Reply) (Go Down)

OOP Is Causing Some Problems, I Need Help by donjo2(m): 6:47pm On Nov 20, 2019
Hi programmers,

I have heard so much about the importance of implementing OOP in projects across the various PLs.

Equally, I've tried wrapping my head around this concept. Somehow, I feel I'm missing something.

So, I have decided to speak out.


What are the building blocks or basics of OOP? What do I need to know first?
Re: OOP Is Causing Some Problems, I Need Help by OlamigokePhilip: 7:03pm On Nov 20, 2019
Understanding Object-Oriented Basics


OOP has a reputation for being complicated, but I think it's actually simpler than some of the concepts you've
already learned. In fact, OOP allows you to represent things in your programs in a way that's more like the real
world.
What you often want to represent in your programs—anything from a checking account to an alien
spacecraft—are real-life objects. OOP lets you represent these real-life objects as software objects. Like real-
life objects, software objects combine characteristics (called attributes in OOP-speak) and behaviors (called
methods in OOP-speak). For example, if you were to create an alien spacecraft object, its attributes could
include its location and energy level, while its methods could include its ability to move or fire its weapons.
Objects are created (or instantiated in OOP-speak) from a definition called a class—programming code that
can define attributes and methods. Classes are like blue-prints. A class isn't an object, it's a design for one.
And just as a foreman can create many houses from the same blueprint, a programmer can create many
objects from the same class. As a result, each object (also called an instance) instantiated from the same
class will have a similar structure. So, if you have a checking account class, you could use it to create multiple
checking account objects. And those different objects would each have the same basic structure. Each might
have a balance attribute, for example.
But just as you can take two houses built from the same blueprint and decorate them differently, you can have
two objects of the same class and give each its own, unique set of attribute values. So, you could have one
checking account object with a balance attribute of 100 and another with a balance attribute of 1,000,000.

Excerpt from O'reily Python Programming for the Absolute Beginner by Michael Dawson
Re: OOP Is Causing Some Problems, I Need Help by zubydave(m): 9:26pm On Nov 20, 2019
Look here, aside the traditional definition of OOP, here's what I've got to tell you on this; OOP is just a concept used to make coding and concepts easier by grouping related action together to form a single entity. Eg all math related actions or codes are packed or bundle together to form a single unit. Now you use part of this entity to do certain things you already defined by calling the object methods. I hope this helped
Re: OOP Is Causing Some Problems, I Need Help by Nobody: 11:31pm On Nov 20, 2019
Check my previous post on OOP, ask questions where you don't understand.
I'll soon update the post
Re: OOP Is Causing Some Problems, I Need Help by progeek37(m): 11:32pm On Nov 20, 2019
donjo2:
Hi programmers,

I have heard so much about the importance of implementing OOP in projects across the various PLs.

Equally, I've tried wrapping my head around this concept. Somehow, I feel I'm missing something.

So, I have decided to speak out.


What are the building blocks or basics of OOP? What do I need to know first?
Don't start learning OOP with Python or JavaScript, if you do your brain will crash.
I will encourage you to First learn OOP with Java or C# and then switch to Python or JavaScript, everything will become clear. This is not a rule, but it is my own advice.
You can't learn programming in isolation why not join my tutorial group on Java which is done via the Zoom app which allows sharing of computer screens? Check out my posts.

To give you preview of what an object is.
The term object is an encapsulation of methods and data
And I believe you used many of them before.

private String name;
private int age;
private String country;
Things like string name, int age etc are called data. We could also have an object as data like
private Department department;
public class BioData
{
public BioData ()
{
this.name = "John Doe";
this.age = 45;
this.country = "USA";
}
public BioData(name, age, country,...)
{
this.name = name;
this.age = age
this.country = country;
...
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public String getCountry()
{
return country;
}
public String displayPersonalInfo ()
{
return String.format("Name: %s Age: %d Country: %s", this.name, this.age, this.country);
}
Things like getName(), getAge() etc are called methods in Java, C# has properties that define the above methods in a special way using get and set keywords.
Here is a method that truly defines an action:
public boolean validateAge()
{
boolean isValidAge ;
if(age < 0 || age > 150)
{

isValidAge = false;
}else
{
isValidAge = true;
}
return isValidAge;
}
Assuming all the code resides inside a class called BioData.
We could do something like this
BioData newstudent = new BioData(name, age, country...)
newstudent.getName();
newStudent.validateAge();
newstudent.displayPersonalInfo();
Something like newStudent is called an object that is the materialized version of the class. A class is a prototype that defines the general attributes of an object. Just like bakeries use mould to produce bread, the mould where the mixed flour is poured and heated to produce bread is a class but the bread thus produce is an object.
I have many things to say but no facility to explain it here.
In conclusion an object in its essence is simply a combination of methods and data.
Data defines the characteristics like if you have a class called Dog. You may have a data called colour that defines the appearance of a dog object. On the other hand Methods define object behaviour e.g dogs objects can "bark".
Why not join my Java tutorial?

2 Likes

Re: OOP Is Causing Some Problems, I Need Help by Nobody: 8:58am On Nov 21, 2019
Get a for dummies book simple.

(1) (Reply)

What’s The Difference Between Web Hosting And Domain Hosting? / What's The Cost Of Getting And Maintaining E-commerce App For Apple And Android / Experience Php Developer Needed

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.