Object-Oriented Basics

--Originally published at TC201 Winter 2016 Jorge

Object-Oriented Basics

 

I just watched video. It talks about specific things only object-oriented have such as objects, classes, inheritance, multiple inheritance, overriding, constructors, etc.

I think this vas a very interesting video since it explains everything on it step by step in a simple and understandable way.

I think it's cool we've got to watch this video at this point of the semester because it helps us get prepared for the masteries and upcoming wsq's.

The cool things about objects is that they all have state and behavior. It's like you can create living beings and you can make them interact with each other. That's also why OOP is harder than non objecr-oriented programming languages.

With that being said, I hope to learn the Java language as much as I can. So let's go!

#WSQ03

--Originally published at Programación Orientada a Objetos

Mi opinión sobre el video es el que la programación orientada a objetos y la programación estructurada, tienen sus puntos a favor dependiendo para que lo quieras usar. En la mayoría de los casos, la programación estructura es preferible en casos de querer hacer una cosa sencilla, como por ejemplo un “Hello World” es más fácil de hacer en Python que en Java; por otro lado en el caso de querer hacer por ejemplo un programa que te diga la hora de distintos países y ciudades, es preferible hacerlas en java. No se puede decir que un tipo de programación es mejor que la otra, solo se trata de usarlas de manera conveniente.

El encapsulamiento es muy usados en la programación orientada a objetos, ya que nos sirve para tener un código más seguro y flexible, esto quiere decir que nos permite poner instancias ya sean: private, protected y public, lo cual hace que sea más fácil para el usuario y los programadores con respecto a lo que pueden usar.
Private significa que ese atributo o método, solo se podrá usar dentro de esa clase.
protected significa que ese atributo o método se podrá usar si se encuentran todos dentro del mismo paquete.
public significa que pueden ser usados por cualquier clase o método.

Inheritance es lo que llamamos herencia. Las herencias nos ayudan cuando tenemos objetos con características comunes entre ellas, por ejemplo los medios de transporte, todos tienen muchas características en común, como transportar gente, tienen llantas, etc. Así que cuando una clase hereda de otra, una se convierte en la clase “padre” y la otra clase “hijo”, la clase hijo heredará todos los comportamientos de la clase padre.


#WSQ03

He-he, POO, he-he

--Originally published at Ce qui est chouette

Watched, the video lies. Learn, I have.

Inheritance sounds cool and quite useful, is-a and has-a relations were easy to grasp. Example: Coffee has caffeine [has-a], coffee is a beverage [is-a] (shoutout to codecademy’s course on Java, which I’ve finished).

That’s about all I have to say about that, here are some pics of a test program I wrote using inheritance -in classic OOP manner, he-he POO. David Bowie (Major Tom) is-a singer ;) gotcha.

He-he, POO, he-he
I know I’m a little late on the Bowie train.
He-he, POO, he-he
But I ain’t going off the rails #ozzy

The jokes are insane, as we lie aboard a crazy train.

-Lil’ about guy.


He-he, POO, he-he

He-he, POO, he-he

--Originally published at Ce qui est chouette

Watched, the video lies. Learn, I have.

Inheritance sounds cool and quite useful, is-a and has-a relations were easy to grasp. Example: Coffee has caffeine [has-a], coffee is a beverage [is-a] (shoutout to codecademy’s course on Java, which I’ve finished).

That’s about all I have to say about that, here are some pics of a test program I wrote using inheritance -in classic OOP manner, he-he POO. David Bowie (Major Tom) is-a singer ;) gotcha.

He-he, POO, he-he
I know I’m a little late on the Bowie train.
He-he, POO, he-he
But I ain’t going off the rails #ozzy

The jokes are insane, as we lie aboard a crazy train.

-Lil’ about guy.


He-he, POO, he-he

Objects in #WSQ03

--Originally published at miguelmzbi

“No object is so beautiful that, under certain conditions, it will not look ugly.”(Oscar Wilde)

I agree to that quote, I started to work on my Puppy class and it looked really nice, but when I reached the point where my knowledge of OOP that I learned in Python ended (Or that I forgot), things got ugly. ;-;

But thank you Codeacademy, Kassab and Ken, I now remeber and can make an OOP basic code.

<<Post not finished. Working…>>

 

 


Objects in #WSQ03

WSQ03

--Originally published at chozaoop

Ok so the author here reviews some basic concepts of Object-Oriented Programming, some of these were already reviewed on one of Ken’s classes, but personally i gained some new knowledge here.

All the “snips” and annotations i’ll be taking are from this video. Since i liked the images he used for explaining the concepts, they seems clear and simple.

Encapsulation:

WSQ03

“The idea of encapsulation is simply that the fields of an object, an instance should only be read or written by methods of that instances class…”

“If we want to read or write one of these fields, we should not do so directly from outside the object, only the methods of the class should be directly reading and writing these fields from outside the class, externaly we only interact with the fields indirectly by invoking the methods, the thinking here is that we create a class, the methods you give that class ENCAPSULATE the encompass all the knockledge of what is meant to be done with the data that makes up that data type…”

Inheritance:

WSQ03

“The idea of inheritance is simply that some data types, some classes may overlap, such as that one data type has all the same stuff found in another…”

So in this example above the Cat class inheritances from Mammal and them both inherits from Animal, which means that the Mammal class automatically inherits all of the members from the animal class, and so, the Cat class inherits the members from both of above, even if when you wrote the Cat class you only specified “F” and “G”.

We could say that Mammal and Cat are subtypes of Animal, and Cat is a subtype of Mammal, and so, Animal would be a supertype of Mammal and Cat, kinda easier to say Parent and Child.

Also, let’s say it like this, the Animal class has some methods or states which could be Eating, Sleeping and Breathing, Mammals also have these properties BUT, Mammals also have some “unique” properties such as, hot-blooded or furry idk, but also Cat has some properties which Animal and Mammal don’t such as Purring or Meowing.

Is-a vs. Has-a:

WSQ03

Here we ought to ask ourselves, is a relationship between these two classes an “is-a” relationship or a “has-a” relationship, like the past example, Mammal class was a more specific type of class than Animal, that’s a “Is-a” relationship, which is a proper use of inheritance.

Another example is about a car, a car is composed of many parts, let’s say that we have a Stereo class, and we have a Car class, then it would make sense that the Car class has a “Stereo” field, which is a “Has-a” relationship, since it calls for composition.

It would not make sense to have the Stereo class inherit from the Car class, because the Stereo is not a kind of Car, nor the other way around either, because the Car is not a kind of Stereo, if we were going to extend the car class we would do so as something like: Ford or Sedan or Jeep, something which is a Car, just a more specific type of Car.

Polymorphism:

WSQ03

Ok so here i’ll explain it myself, let’s say we create a method called foo(), in the class “Jack”, Ted inherits is but then we create another one called also foo() in Lisa, then Kate and Mike inherits this, if we call a Kate, Mike or Lisa object, this will invoke the foo() method created in Lisa, but if we do so from Ted or Jack, it will call the method created in Jack.

Kind of vague explanation of Polymorphism, i understand that the word itself means “changing forms”, i might ask Ken for help throught the week or even via Twitter.


WSQ03