Jump to content

Java and OOP


obasan

Recommended Posts

All these links and not a single ELI5 :gnome: Let me take a shot at this dad.

So encapsulation and abstraction is very similar. It is kind of like putting a part of the program into a container, it limits the scope of the program and the information that can be obtained by the program. Why is this important? Well, for encapsulation, private components of your program are should only affect certain parts of your program and should not go beyond that. For abstraction, it is hiding the details of the program to the user. For example, let's take an example of a person who deals cheese of the street (cheese is good). All you want is the cheese, the dealer has a billion small characteristics to him that are unnecessary and are better off not knowing. All you really need to know is the price of the cheese and how to pay him, simple.

Inheritance is similar to real life. Let's take the example that all llamas are mammals. It is inherent to all mammals that they have fur, are vertebrates, are warmblooded and endothermic, etc etc. The same is true with llamas and all other mammals, they all have these characteristics. But llamas also have unique characteristics that distinguish them, their look, how they sound, and their overall majestic aura. So imagine mammals is the superclass (like the parent), and the llama program is the subclass. You would define the characteristics of the superclass and the subclass would automatically have these traits by extending the superclass and more if you add them. There's more to it, but the easiest way to understand it is to first understand the relationship between objects.

Polymorphism is an odd subject, the big one that I think you really need to know is subtype polymorphism. Essentially, you can logic this out.. If A is a subtype of B, an A can do anything a B can do. So let's take the example of the llama. If all mammals have the ability to make milk for its offspring, then conversely llamas can make llama milk for its babies as well. But you can't go the other way around, not all mammals can be as majestic as llamas.

I'm typing on my phone so idek if i'm right, somebody correct me if i messed up but this is the basic parts of the concepts you asked for ^_^

GL learning, it's not that bad once you get into it.

  • Like 1
Link to comment
Share on other sites

Programming has a whole bunch of funny names for stuff, but it's actually so simple and Alek's post pretty much wraps it in a nut-shell. But there's a back story which'll give you a better understanding for why we need OOP.

The short-and-sweet is:

  • Computers aren't OOP. They beep and they boop as they process one instruction at a time in their machine language.
  • Computers can't OOP without memory.
  • Memory lets the computer store 1's and 0's in such a way as to keep the info intact for as long as needed.
  • Machine code referrers to that chunk of memory as many times at called.

The machine language/lower level languages can't OOP. But languages built on-top of those can and do.

  • Like 1
Link to comment
Share on other sites

On 4/8/2017 at 2:10 PM, Alek said:

Inheritance 101:

interface Animal {

int getAge();

}

class Dog implements Animal {

int getBarks();

}

class Cat implements Animal {

int getWhiskers();

}

Dog doggo = new Dog();
doggo.getAge();
doggo.getBarks();

Cat cate = new Cat();
cate.getWhiskers();
cate.getAge();

 

didn't understand shit LMAO.

jk i get about 70% of it...

 

nonetheless, i'll continue learning and one day i'll restore botting to its former glory!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...