[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Object Oriented Programming

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 12
Thread images: 2

File: wordpress-oop.jpg (49KB, 400x277px) Image search: [Google]
wordpress-oop.jpg
49KB, 400x277px
Can you explain how OOP works?

I tried a couple tutorial but they are all about cats and their 4 legs or about fuckin cars and so I have no idea how to use OOP in real applications.
>>
I made a OOP program. Kind of a noob here but I'll explain my understanding.

So classes define objects that know things and can do things.

For my programming class I had to simulate an ATM using OOP, so I've got this ATM class/object, it knows the following:
- The path of the database with all the user pins and money and stuff
- All the user instances it has in a list
And how to do this stuff (methods):
- Read data from the database
- Run (present user menu and process input)

When it reads the user data, it creates instances of another class called User and stores them in a list. Each user knows this stuff
- the users pin
- the users id
- the users Checking account (Account instance)
- the users Savings account (Account instance)

and how to do some other stuff. I dont know man just write a program, fuck you, fuck OOP
>>
>>57858279
jesus dude, just go to school

web classes are not good classes
>>
>>57858279
It's pretty simple. It's about creating subclass or common methods for variables or objects that you will need to create in your program and they will be pretty similar.

For example, if you want to create a program that contains Pokemons, you create a subclass "pokemon", where you specific that all pokemons will have a integer data call "level", a String that will be the name, etc.

Also it can help you avoiding future mistakes, for example, in the class pokemon you can make that if you add a pokemon with an impossible level (like 520) the program will forbide you to do that.
>>
>>57858279
it's all about dividing your code in little chunks of code that interact between each other. And to reuse code you use inheritance.

Also, read a book (pic related) there is not much you may learn with internet tutorials.
>>
So why do you need a class when you make a connection to the database? I mean, there is no way you gonna use an instance of that class somewhere else. Why don't you just write your connection without creating a class, just line of codes one after another?
>>
>>57858526
When using a class, you can interface all sql queries to the database through the class.

ie:
my_db = new Db(credentials);
data = my_db.query('select name, pass from users');
>>
>>57858279
Do you know any other paradigm? Is actually just a matter of scope.

An object is a scope, it may contain procedures and variables.

The procedures side effects are usually restricted to the variables within the object scope.

To access a objects variable, you have to specify an object and the variable. The variable can be for the objects procedures use only or can be globally accessible.


You can think of classes and objects as procedures:

def foo(bar)
return bar

x = foo(1)

y=foo(2)


In that example, the function 'foo' is a class, it's a template for a object, says what variables and procedures the object will have.

x,y are objects. Each of them has a internal variable that in this case are only internally accessible. The 'bar' from one function is not visible to the other function.
>>
it's a tree OP

myObject
\length -> func() { return 20}
\width -> func() { return 10}
\half -> func() { return this.width/2 }
\area -> func() { return this.length * this.height }

myObject.length
// returns 20
myObject.height
// returns 10
myObject.width.half
// returns 5
myObject.area
// returns 200



This is a really dumbed down example btw.
>>
>>57858279

I have a Server Class

A server may have 3 or 4 higher order threads that run a threadpool for lower order threads.

Try any .NET/concurrency stuff and OOP is basically mandatory
>>
>>57858691
>calling methods procedures
>>
Honestly go to school or get a tutor

Last year I tried to learn oop by myself as well and I didn't get anything but after I started my cs class, shit made perfect sense the moment I was taught it thanks to my teacher and non shitty PowerPoint and examples
Thread posts: 12
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.