Index

Get the Object Up & Running


Almost any problem has a mix of simple and complex. Start with the simple.

Start with the simple and get your core object working.

As an example, let's say that your problem calls for you to write a class with one instance variable and eight methods. Here is how we might approach it:

Wow! That's good progress. 👍🏽

Add More Behaviors to the Object


Next steps:

Attacking the More Complex Methods


Now let's start to tackle more complex parts of the problem. Similar how we took a "divide and conquer" above, we can do similar with any more complex method.

Example problem: We have a method named "myMethod" that receives one method parameter (an index) which is an "Integer" object (not "int"). The index may be positive, negative, or null.

Let's assume that our instance variable is named "list".

The positive index (zero to list size minus one) we understand right away.

So our approach is:

Good progress! 👍🏽


Now let's tackle the negative index. Let's assume that -1 really means the index (list size-1), -2 really means the index (list size - 2), etc.

Here we go:

The algorithm for "convertIndexToRegular" is not too bad:

That's All! 🤸🏽

Tackling Generics


If there is a generics aspect to the problem, and we are clear on how the generics should be coded, then we may as well code it in right away. However, if we're not clear on the generics, first code up the object without generics to get it up and running, and add the generics after words. Here is some guidance....