When I started my journey with Object Oriented Programming I quickly found out many tutorials and trainings, which showed how to use OOP structures in code. Unfortunately, most of them demonstrate only how to write your first own class, interface. How to create an object. All of this was about language “grammar”, about key words, the way how to create structures used in OOP, etc. Yet, somewhere authors lost the most important information to share - why we decide to do this instead of looking for other solutions? Why an interface contains nothing more than abstract methods? Why all of those are public? What for are those visibilities? And so on...
Tuesday, December 30, 2014
Friday, December 5, 2014
What diagrams can tell you
let’s talk about diagrams
I know that many of you may feel sick at the very thought of UML’s, but, whether you want or not, in certain moment of your career you will have to work with them and, what’s more frightening, there’s a chance that you will have to create them on our own.Why so many programmers don’t like diagrams anyway? Well, I think it’s because of some kind of unwillingness towards something unknown, in this particular case – to the language which is unknown for us. Because that’s what UML really is, a language that isn’t understandable by all of us. It’s a language that not each of us “speaks”.
However, today I don’t want to write about this.
It happens in each language, sometimes we can know essence without deep investigation of details. We just know, that in each sentence there are less important words, as well as those words which matter most.
It’s exactly like with those sentences with word “but” inside. We all know that everything that stands before “but” is irrelevant and the real sense is just after :) And that’s what I want to describe today: cases, when you don’t have to look deeper to understand the context. A quick look at a diagram is enough to get the hang of what is the most important in it.
Labels:
clean code,
code quality,
design,
ooad,
oop,
UML
Thursday, June 5, 2014
Overriding - let's check how it works
what is method overriding?
Method overriding is a concept based on polymorphism which allows us to create a method with the same signature as in parent class to extend or change its behaviour. Let’s take a look at the definition:
Method overriding - allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. The implementation in the subclass overrides the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.
Today we will check what is possible to override and what's not. I will also try to explain why it is so.
Sunday, May 11, 2014
Take a look at Local Classes
what will it be about?
Recently I tried to explain what nested classes are and what you can do with them. There were a few words about Static Nested Classes and Inner Classes. I've also mentioned that there are two more types, which are special kind of Inner Class. And today I want to write something about one of it - Local Classes.Ok, that's all great, but what Local Class is?
Local classes - classes that are defined in a block, which is a group of zero or more statements between balanced braces.
Which means that you can define a Local Classes inside any block.For example you can define a Local Class in a method body, a for loop, or an if clause.
Sunday, April 6, 2014
Take a look at Nested Classes
what will it be about?
After a few posts about Enums I want to present you another interesting feature of Java which is Nested Classes.In next a few articles I will try to introduce to you inner, static nested, local and anonymous classes. Of course, everything with usage of TDD :)
I will start with some basics - how to create a particular type of class, what is allowed and what's not. After introduction we will move forward and I will present some code which will show the ways of usage of those classes and, what's more important, the problems that result from their use.
I've gathered some material, I wrote a couple tests and it's turned around there is more text and code than I expected. That's why I decided to split it into a few shorter posts. Hopefully next ones will be published shortly, everything depends on how fast I will have a possibility to edit them.
Monday, March 10, 2014
Enums - what can go wrong?
In last two posts I showed you what enums in java can give us and what we can do with them. I hope that right now you will agree with me that enums are really powerful.
Today I want to present you a few things which you can treat as a warning sign whenever you will see something like this in your own code.
But you need to remember that it's just a sign, nothing more. It doesn't mean that you shouldn't solve your problems in presented ways, it would be enough to take a deep breath, look at code once again and then made decision if it should be changed or not.
On the end of my last post I asked a couple of questions about examples given by me. If there was something worrying in them? Were they good or not?
Today I will try to explain why I asked those questions and I will share with you my thoughts about problems that can occur when we are overusing enumerations.
Let's start :)
Today I want to present you a few things which you can treat as a warning sign whenever you will see something like this in your own code.
But you need to remember that it's just a sign, nothing more. It doesn't mean that you shouldn't solve your problems in presented ways, it would be enough to take a deep breath, look at code once again and then made decision if it should be changed or not.
On the end of my last post I asked a couple of questions about examples given by me. If there was something worrying in them? Were they good or not?
Today I will try to explain why I asked those questions and I will share with you my thoughts about problems that can occur when we are overusing enumerations.
Let's start :)
Labels:
abstract,
abstract method,
enum,
enumeration,
java,
ooad,
oop
Friday, March 7, 2014
This powerful Enum - part 2
let's move on
Recently I wrote about basics of Enums and when we finally knows them, we can take the next step and look how powerful Enums in Java really are.Today there will be more code, mostly covered with tests to prove that it works as I wrote :)
Tuesday, February 25, 2014
This powerful Enum - part 1
a few words at the beginning
Today we will take a look at Enums in Java. Let's start with a definition:
Enumeration - a collection of items that is a complete, ordered listing of all of the items in that collection.
Sounds simple isn't it? Even if, Enums in Java allows us for many things and it's a really great language's feature, which can increase quality of our code.Monday, February 17, 2014
What happens in try-catch-finally?
let's talk about basics
Try-catch is the most popular way to handle exceptions and with finally block you can really make your code cleaner and make life of all developers who will use it - easier.As usual I will cover whole code with tests to proof that it works as expected (this time without TDD, because it wouldn't give us any advantages).
Subscribe to:
Posts (Atom)