Polimorfismo em Java

Na unidade 6 do curso de Programação 1 aprendemos o conceito de polimorfismo, termo derivado do grego poli — muitos —, e morpheus — forma, estrutura. Uma das tarefas é discutir polimorfismo no contexto de programação orientada a objetos e dar um exemplo de como implementar essa funcionalidade em Java.

Revisando as anotações achei que a minha abordagem foi interessante. Segue para a apreciação, com pequenas modificações.


The world around us is polymorphic. We can see this almost everywhere: people, animals, cars, books, languages, houses. As humans, we seek to differentiate ourselves from others. We like to think and show that we are unique up to a point in which other people still recognize us as humans. Up to a point that they still can relate and interact with us.

Something similar happens with a programming language like Java. The ability to instantiate and handle multiple objects together make complex programs easier to handle, manage and develop. It is expected that complex software keeps evolving and including new functionalities with time. Imagine that if for each new functionality you have, you need to review previous objects and update old code to fit each new features included. It can easily become a complex and time-consuming task. Polymorphism is a powerful solution that avoids a lot of code rework and guarantee program fluidity. Citing Oracle Java documentation definition, “subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.” (Oracle, 2017)

Imagine the following Language superclass and English subclass.

class Language {
    void toHear(Language hear) {
    // Method to hear some language
}
toSpeak(Language speak) {
    // method to speak some language
    }
}

class English extends Language {
	void toHear(English hear) {
	// specific instructions to hear and understand the English language.
	}
	toSpeak(English speak) {
	// specific instructions to hear and understand the English language.
	}
}

Imagine that in the example above you have multiple language subclasses and want then all to “work” in their own language. Of course that this is a simplified example, but the same method toSpeak would call a specific response for each object (aka each language), a unique behavior, while still sharing some functionality from the parent class.

Reference: Oracle (Ed.). (n.d.). Polymorphism. Retrieved October 18, 2017, from https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html

Programming 1 – Learning Journal

Escrevi isso no diário de classe de Programming 1 na University of the People. Idos de 2017. Estou revisando minhas anotações para o texto sobre o curso e achei interessante compartilhar isso aqui em separado. Segue.

Learning Journal – Unit 4

The process of developing a program with subroutines was very enlightening to me in the overall programming learning process. If in the Programming Fundamentals course we were presented to conceptual models like flowcharts and pseudocode, now we actually use the tools that break the problem into manageable steps and make complex ideas possible to handle.

I know that it can be a naive feeling, but it is a realization that programs are simpler than I originally imagined. Not in the sense that they are easy. Now it is also much more clear to me the amount of effort behind complex software and systems. But they are done in manageable steps. There are several foundations done many years ago that are still used as the basis to systems that are developed nowadays. I do not remember quite well where I read the phrase from one of the Unix OS developers that was surprised by seeing lines of his code in almost every operating system that we use today.

There is this concept of the human colossus: the realization that we build everything on the shoulders of many scientists and inventors that came before us. Being a “genius” in that sense is always a humble process. Humanity is a collective effort and somewhat this is especially intense when we study software development.

As you can see, my feelings on this unit are more philosophical. Routines and subroutines building on top one of another. Black boxes and the recognition that a lot around us have mysterious internal dynamics that we simply do not think about, just trust, use, and even put our lives on its hands. This makes me understand the importance of the work that I might decide to do and the projects that I might get involved in the future. In our times, lines of code can save many lives, but they also can kill many. If in the last learning journal I talked about the importance of studying math to be a better developer, now I see the importance of philosophy and ethics behind what we do and the tools that we have at our disposal. It should not be only about a good job and salary. I must be about us all, the humanity and the human colossus.

University of the People no Brasil

Amanhã começa o período 1 de 2017 na University of the People (ou UoPeople para os mais chegados). Será meu sexto período desde que comecei a cursar Ciência da Computação em junho de 2016. Com 18 pontos de crédito ainda sou considerado “calouro” de acordo com o catálogo da universidade. O caminho para percorrer ainda é longo.

Desde que comecei o curso me chamou atenção a baixa quantidade de estudantes brasileiros envolvidos e o interesse estável no Brasil. De 2016 para cá vi pouca diferença nas comunidades internas da faculdade e no grupo de estudantes no Facebook. As matérias sobre a universidade em português são raras e a maioria é de mais de ano. Acredito que o inglês seja uma barreira para muitos, mesmo assim temos um potencial muito maior de envolvimento considerando nossas dimensões e população.

Essa é a segunda tentativa que faço de criar um blog pessoal para compartilhar meus estudos, discutir assuntos de aula e do mercado e estimular a comunidade de estudantes brasileiros em cursar uma faculdade à distância no exterior. Com um pouco mais de ambição espero que esse espaço se torne um dos muitos agregadores de discussões e projetos. Não faz sentido cursar uma universidade sem motivo, sem uma razão construtiva. Que esse espaço sirva de catalizador para mim e para colegas na longa e árdua jornada do estudo superior online à distância.

É comum começarmos projetos cheios de ideias, estrutura, pré-requisitos e afins. Sinceramente minha experiência passada mostrou que excesso de planejamento paralisa. Meu objetivo desta vez é manter as coisas simples, atualizar diariamente e fazer melhorias aos poucos. O primeiro passo é importante, porém constância é essencial.

Bem-vindos!

Para saber mais sobre a universidade recomendo os links abaixo:

University of the People – http://www.uopeople.edu/

Grupo de Estudantes da UoPeople no FacebookLink