Abstraction & Encapsulation

--Originally published at diegotc2016


For example if I say a table you understand the concept it does not matter I I said it was a wooden table or a glass table. Abstraction means that we focus of the certain qualities of something. You have to take what is relevant. For example the taste of a table or the smell of a table are irrelevant

Abstraction & Encapsulation


Encapsulation can be defined by the fields of an object and class should only be read or written by the method of that class. Hide some parts of the code except for a few that are most necessary. For example a phone , you don’t care how your phone works, you only care that you can take pictures with it, use apps, watch videos, hear to music, etc.

Abstraction & Encapsulation

I got this out of lynda.com Foundations of Programming: Object-Oriented Design by Simon Allardice


Abstraction & Encapsulation

Some other concepts

--Originally published at chozaoop

Happy Valentine’s Day!

So in this post i’m gonna share the remaining OOP theoric concepts that will be featuring in partial #1 exam. Mentioning them and then referencing the source, if you like the explanations and would like to copy them you are free to do so, if you have a comment, leave a comment please, ya know, Ken likes discussion.


What is abstraction?

Abstraction is process of hiding the implementation details and showing only the functionality. Is used to hide certain details and only show the essential features of the object.

You implement it like this:

“abstract class <class-name>”as creating an abstract class

and as for a method “abstract public void <method-name>;”

This concept kinda relates to encapsulation, since encapsulation means hiding information inside the object, while abstraction deals with the outside or the interface.

Encapsulation = Object Internally —–Abstraction = Object Externally

An Abstact Class cannot be instanciated, and an Abstract method is a method which is declared without implementation.

An Abstract class and a Final Class have the opposite meaning.

When do i use it? When i know that i need to implement something, but not exactly what it is or how it should look like.


Java Visibility Modifiers

            | Class | Package | Subclass | World
public      |  y    |    y    |    y     |   y
protected   |  y    |    y    |    y     |   n
no modifier |  y    |    y    |    n     |   n
private     |  y    |    n    |    n     |   n

y: accessible
n: not accessible

Really nice table.

Default: This one might be a mistake, it means adding no access modifier. As you can see on the table, only available this class or a class in the same package, it is not available for subclasses or the rest of the world.

Public: Available anywhere, any other class, subclass or even any class in the world, this one provides the most access while private provides the least.

Protected: I see this one as using the class inside your own works, i mean if you create a package and a class and then a subclass, protected modifier keeps any foreign intruder away, but still making it available for you.

Private: PRIVATE EYES! This modifier only allows access from the same class, no other package, subclass and obviously the rest of the world.

So remember:

Public > Protected > No Modifier > Private.

From most access to least.

Ok so the purpose of using these modifiers is, well, controlling the access to your member variables and functions, whether it is in your own program or most importantly, the outside world.

We do give it a use sometimes in this course but it’s really really important to know how to use these when making a big project since you never know who wants to mess up your stuff and if you know how to use modifiers it should keep you safe.


Some other concepts

Masterie: What is abstraction?

--Originally published at Alan TC201

Abstraction in Java is like for example talking about animals, this is abstract because you do not know the context of that animal, it can be a cat, dog or a monkey, but you only know that it is animal.

Masterie: What is abstraction?

Abstraction has the same proces of hiding the implementation details from other people, only the functionality will be provided to the user. In other words user will have the information on what the object does instead of how it does it. Or in other words is telling the people the basic, hiding all the complex process that it requires.

In Java you can create an Abstraction using Abstract classes and Interfaces.

“Abstract Class

  • A class which contains the abstract keyword in its declaration is known as abstract class.
  • Abstract classes may or may not contain abstract methods ie., methods with out body ( public void get(); )
  • But, if a class have at least one abstract method, then the class must be declared abstract.
  • If a class is declared abstract it cannot be instantiated.
  • To use an abstract class you have to inherit it from another class, provide implementations to the abstract methods in it.
  • If you inherit an abstract class you have to provide implementations to all the abstract methods in it.” (http://www.tutorialspoint.com/java/java_abstraction.htm)

Masterie: What is abstraction?

Taking the example of the animals again, you can have a class name Animal and that class is going to be abstract, it has inside methods that all animals do, they eat and an abstract method that says that animals move.

Masterie: What is abstraction?

Then you have another class name Dog that extends from the animal class so the Dog class has in it the method eat, because all animals eat, but there is also an abstract method that the dog class need to verify, the move method, because not all animals move the same way, ones fly, otherones swim and dogs walk in four legs, so the method move this to be verify in the Dog class.

Masterie: What is abstraction?

Now that you have the dog class in is possible to create another class, that extends from the animal class, this new class is going to be a bird, birds can eat, but they move by air while using their wings.

Masterie: What is abstraction?

Finally the main class that controls the other classes and send them inputs to receive outputs.

Masterie: What is abstraction?

Links with more info:


Masterie: What is abstraction?

Cheryl, probably, was a nice gal. Probably not

--Originally published at Ce qui est chouette

Ken…you did this to me…you ruined me. Information, regarding Lychrel Numbers, gathered from…oh, god…Wikipedia.

Lychrel kind of an anagram for Cheryl, Wade VanLandingham’s girlfriend. This Wade guy sucked at making up names.

“¿Qué debería poner?” pregunto yo acerca del blog.
“2” responde Marijose Dávila Diosdado, A01630826, de TC101 Winter 2016.


I feel the term playground has not caught up with many of my beloved readers -actually, I only have one reader, Miguel, notice me, Ken D: -so here I go: playground refers to the place where the little object boys and little object girls go play around, show off their methods -totally not a euphemism -and meet class instances, imports and guys of the like. It’s like a playground, but for objects, from classes…and then I, but he said and I go ooh ooh, you go aah aah, Lalalala, Ah Lalala

Back to business, or basics, here’s the playground and the console:

Cheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably not

Now, on with the foolishly long code for the class Lychrel:

Cheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably not

Once again, I’ve defeated the evil corporation of WSQ’s. I’ve mastered the mastering masteries, Master -they’re to the left of the post.

“Onwards, noble steed!”

-The about guy.

Cheryl, probably, was a nice gal. Probably not

Hit me Baby(lonian) one more time

--Originally published at Ce qui est chouette

So, how did I do the Babylonian Method one, that’s the question, isn’t it?

What I did was: I reused the class “SuNumero” from the last WSQ – Euclid’s Method -and added, in a public float, the method that would be used for the Babylonian Method.

So, in essence, I implemented the method in a:

‘”Hey, Ser Object, what’s your square root?”, and it would reply “Oh why my square root is *this*, I got it using the Babylonian Method”, and it said…and I said…one thing led to another and there we were, leading the Bolshevik Revolution, I mean…coding, in Java. Yep.’ way.


Here are some screenshots of the playground, the added method, the console, and the Joker and the Thief of the night:

Hit me Baby(lonian) one more time Hit me Baby(lonian) one more time Hit me Baby(lonian) one more time

So, that was all. Things were learnt, java was written, all was lost, but war…war never changes.


-The about guy.

Hit me Baby(lonian) one more time

Euclid’s Choice

--Originally published at Ce qui est chouette

Instead of choosing between his two offsprings [as Sophie], Euclid didn’t have  a a choice, like, at all; this was a bad attempt at making Euclid’s Method fun. I’m not saying that it ain’t so, just that…well…you get it, it’s hard, making math fun when it doesn’t have a cool name.

On with the WSQ.

Here’s the code for the “playground” -because classes play there and stuff -and the console output.

Euclid’s Choice

Euclid’s Choice

Demonstration, at least, of some grasp of OOP and abstraction -because of the perspective.

Now, the class SuNumber:

Some encapsulation knowledge. On with some theory: encapsulation is the process through which information regarding a class is kept “hidden” -unusable outside of the class itself. It is represented in Java through the use of the words “private” or “public” in the object’s attributes or methods.

Euclid’s ChoiceEuclid’s Choice

Ending the least fun of the blog posts. Euclidean method git got from the guy at Cut the Knot


Euclid’s Choice