This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Learning OO

 
Ranch Hand
Posts: 574
VI Editor Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been programming for some 30, eeek! 40 years now, and have only brushed up against OO without actually using it.  Now I want to actually learn OO.  I've read books, websites, etc so I understand classes, objects, encapsulation, all those fancy words.

What I don't understand is how to think in OO terms.  To do that I need to write programs.  The books/websites I have are typically walls of text, with no problems at the end of each chapter.

Anyone know of any books with problem sets at the end of each chapter?  Or websites with problem sets?

Language?  Kotlin would be great but I'm not holding my breath.  Java would be my next choice, followed by Python, C++, Perl, awk, sed, bash..... (kidding, stop at C++).
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jim Venolia wrote:Language?  Kotlin would be great but I'm not holding my breath.  Java would be my next choice, followed by Python, C++, Perl, awk, sed, bash..... (kidding, stop at C++).


Please clarify something: Are you wanting to learn a language like Kotlin, Java etc or are you wanted to learn how to program using OO practices with a language like Kotlin, Java etc?

There are some things that you can do without much, but a little help here an there.

Here are a few possible projects:

Calculator
A few months back many people where into creating a calculator. This could be an OO program for you to try your hand at.
Each "button" on the calculator could be an child object from an abstract class which implements methods like 'produce value' differently.

Battleship, Chess or Hangman
Some people like the challenge of creating games like Battleship, Chess or Hangman. You can abstract players, pieces, boards and more as parts of those games.
Plus you could implement a "Computer Player" for those games or open them up to the Internet. You don't need to go all out either with these and you could make them command line based or HTML based.

Business
Others like the challenge of creating a inventory management system, or simple banking system.

Adventure
Some of us may remember text based adventure games. This could allow you to have a player object, who can delegate tasks to tool objects.
Tools could be based on an abstract class and some could be offence and others for defense which the rest could be both or neither.

However you did say that you wanted a book and therefore I do have a recommendation or two:

Android Programming: The Big Nerd Ranch Guide (3rd Edition) found here https://www.bignerdranch.com/books/android-programming/
You create three or four different projects through the book and chapters progress the code as you go. All of the code for this is Java code, however you can challenge yourself even more by doing it all in Kotlin.
There are a few OO things in this book, and it may not be for everyone. It focuses a lot on Android development as you may have guessed.

You mentioned Kotlin, so you may be interested in the books found here:
  • https://kotlinlang.org/docs/books.html
  • https://www.safaribooksonline.com/search/?query=kotlin
       *Subscription based, but provides access to many resources

  • I have found that due to the fact that Kotlin is 100% compatible with Java that you can use a Java book as a base, but replace the Java code with Kotlin as you go.
    You can even mix and match allowing you to have both Kotlin and Java source files in the same project.
    Currently this is how I'm trying to learn Spring/Spring Boot and Kotlin.

    There are a number of books and resources listed here https://coderanch.com/c/books which you may not be aware of.

    Hope this helps you out.
     
    Jim Venolia
    Ranch Hand
    Posts: 574
    VI Editor Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I want to learn OO.  I want to learn Kotlin.  Learning OO using Kotlin would kill 2 birds with 1 stone.  But in my question I'm primarily concerned with OO, I want to OO more than I want to kotlin.

    That book looks good, I'll look into it.

    As for Calculator, Games, etc.  Those are the ultimate goal, but if I jumped into them they would not be OO.  I need baby steps to teach me how to class, subclass, abstract, super, etc etc etc.  Trying to put it all together without understanding the pieces doesn't work for me.
     
    Marshal
    Posts: 15870
    265
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Jim Venolia wrote:I've been programming for some 30, eeek! 40 years now, and have only brushed up against OO without actually using it.


    In all those 30-40 years of programming, what kind of programming did you do? What language(s) did you use primarily? What's the most recent language/platform you programmed on and how long have you been doing that?

    I cut my teeth on Structured Programming (BASIC and Pascal mainly, plus a smidge of FORTRAN and just enough C and Assembly to be dangerous). That was back in the late 80s. My first intro to the concept of objects was with Delphi or as some would call it, Object Pascal. I only sank my teeth into Java in 2000. Around that time, I discovered this community.

    You'll often hear/read that OOP is a "paradigm shift" and as nebulous as that phrase is, it actually is just that. OO languages are not just different from structured languages that you may be used to, they are also geared towards a very different way of thinking about problems and how you create the solutions for them. The same radical shift is there when you move from OO or structured to functional style programming. It's enough to literally make your brain hurt, or at least make you feel like it's twisted up into knots.

    A couple of books that I've been recommending a lot lately are:

    1. Understanding the Four Rules of Simple Design by Corey Haines.  It's not a beginner's book by any stretch but I think the problem it discusses—there's only one—is very relatable: Conway's Game of Life. If you supplement your study of OOP fundamental concepts like polymorphism, encapsulation, inheritance with the practical lessons presented in Haines' book, I think you'll get a lot further than most people do in gaining a deeper understanding of OOP. The book uses examples in Ruby which isn't Java or Kotlin but it's close enough. Also, Ruby is arguably a more object-oriented than Java and there are significant differences in the syntax but not significant enough, IMO, to they make the concepts in the book specific to Ruby; you can apply the same principles/ideas in practically any other OO language, perhaps just not exactly as it's shown in the book.

    2. Think Like a Programmer by V. Anton Spraul. This book has some really good discussions about modes of thinking and problem solving approaches that are applicable in any style of programming, whether structured, OO, or functional.

    And most of all, practice, practice, practice. But practice mindfully, and always look for examples of how other people solved the same problem. That's why I like Corey Haines' book, because he presents so many ways of solving a problem and clearly explains the thought process involved in making decisions that lead to those various solutions.
     
    Pete Letkeman
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh, okay, let's see here.

    Not too long ago many people where talking about this book https://coderanch.com/wiki/687381/books/Learn-Java-Easy-Hands-Introduction

    Possibly some of these book reviews can help point you to a good resource https://coderanch.com/f/49/Book-Reviews

    Given your previous programming experience you may be more interested in the OOP design patterns like Factory, Builder etc in which case these site may be helpful:
  • http://www.oodesign.com/
  • https://www.tutorialspoint.com/design_pattern/
  • http://www.vogella.com/tutorials/DesignPatterns/article.html

  • You can probably start becoming productive in Java relatively quickly due to you having some programming experience provided you are aware of how to use loops, if/then/else and functions.
    Some of the syntax in Java can be tricky at the beginning, but usually the IDE will help you along.

    I think (could very well be wrong) that first you should learn some/most of the syntax, then the common/basic language libraries, then you start programming and finally you learn how to apply the OOP patterns.
    The good thing is that many languages use familiar common syntax, probably dating back to C/C++.

    I'm not too sure how comfortable you are with Java, but I do strongly recommend that you are at least somewhat familiar/comfortable with Java before starting with Kotlin.
     
    Jim Venolia
    Ranch Hand
    Posts: 574
    VI Editor Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Junilu Lacar wrote:In all those 30-40 years of programming, what kind of programming did you do?


    Started with Z-80 assembly, went to 8086/68xxx, then C, then C++.  Also picked up Perl/Python/Java along the way.  I feel fairly comfortable in Java as long as I don't have to do graphics.  I'm 100% self taught, I've never taken a programming language class.  I learned structured programming on my own late in the 80s.  I mostly do embedded systems, device drivers, and code to test stuff.


    You'll often hear/read that OOP is a "paradigm shift" and as nebulous as that phrase is, it actually is just that.


    Yeah, that's kinda why I need a book with programming assignments at the end.  Otherwise I'm gonna write some nice C code using Java syntax.  I can "do" OO, and maybe make it look like I know what I'm doing.  Only those who know what their doing will know I'm blowing smoke.

     
    Jim Venolia
    Ranch Hand
    Posts: 574
    VI Editor Chrome Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Pete Letkeman wrote:


    I feel comfortable in Java, didn't think it had a steep learning curve at all.  I can make objects and classes, make subclasses, call methods, inherit, etc etc etc.  What I can't do is think in terms of why I actually want to use them, as opposed to "well, I should make it a class", but then treat the code like C.

    I know about design patterns.  But I need to learn basic OOP thinking before I can use them.

    Actually I may well be asking the wrong question.  Let's start from the beginning:

    I'm an experienced coder comfortable in several languages, including C and Java.  I'm an old fart structured programmer that keeps hearing about how great OO is.  When I write an OO program using classes and such, when finished I always take 2 steps back and realize I've just written a nice C program using Java.  I learn best by writing programs and learning the material in an organized way.  Wat Do?
     
    Junilu Lacar
    Marshal
    Posts: 15870
    265
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Jim Venolia wrote:Yeah, that's kinda why I need a book with programming assignments at the end.  Otherwise I'm gonna write some nice C code using Java syntax.  I can "do" OO, and maybe make it look like I know what I'm doing.  Only those who know what their doing will know I'm blowing smoke.


    I don't think it's the finding problems to work on as much as it is being able to find and compare different solutions that help you get a sense for what's "good OO" and "not-so-good OO".  That's why I like Corey Haines' book so much. He takes so many different angles at the same problem and it gives you a lot of insights as to the different perspectives that you can take when solving a problem.

    You can find lots of resources on the internet for good problems to exercise and hone your OOP skills on. Just search for "code kata" or "coding dojo" and you'll find more than you can probably handle in a year of practicing every day. The real trick to learning is studying what you've done and comparing it with what others have done. What makes their solutions better than yours? How could you have arrived at something similar to their solution? Can you do even better? What were you thinking that led you away from the better version? What didn't you know? What did you overlook? How can you use this new knowledge in other situations?

    If you want feedback on things you've done, post it up in one of the forums here for review. There are more than a few people here who are willing and able to give you great feedback and advice on how to get better. That's why this community is so great.
      Bookmark Topic Watch Topic
    • New Topic