Results 1 to 4 of 4
  1. #1
    arnor is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Learning Java - Switch from structured programming to object oriented programming

    I work as a software developer since many years. I worked with many structured programming languages and I understand the structured way of programming very well (things like loops, conditionals, variables, arrays, functions are a peace of cake for me).

    However object oriented programming is becoming nowadays increasingly important. I just have to learn it. I skimmed a few books and tutorials about JAVA. And I understand what are objects, classes, constructors...

    I like to learn by practice. So I installed eclipse, and decided to write a Car Rental Software.

    I coded a few things, for example used JDBC to connect to MySQL DB, create tables, insert data to tables, select data... Created Classes that represent objects from DB and Methods that calculate penalties when someone returns car too late, etc.

    However I have a problem, I don't understand the concept of OOP good enough. I don't know how many files with classes and how many different packages to create, and how to name them.

    I could write all code in one file, or create a few files... And I'm sure it would work, but it would be another structured code. And I want to create OOP code.

    OOP is very important for me because I understand how powerful it can be. For example encapsulation gives amazing possibilities.

    Now back to the question...

    Short spec - Car Rental Software

    • add/edit/delete vehicles
    • add/edit/delete users
    • vehicle reservation
    • calculate penalties
    • I want to use JDBC with MySQL
    • GUI maybe SWT



    How to divide the program to packages and classes?

    How many packages would you create, how would you name them?

    How many .java files with classes would you create? How would you name them? In what packages would you place them?

    What methods would you create and in which classes?

    From what resources could I learn the optimal way of naming classes and packages? I would be happy to check out a few projects with a top notch class, and packages structure...


    Ps. I'm not asking how to code it (it's simple... JDBC + a few inserts, selects, methods to create reservation, penalties, GUI ). The problem is how to create the optimal OOP structure of the project...

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Learning Java - Switch from structured programming to object oriented programming

    Structured programming allows the code to be 'structured' in some way, i.e. divide the instructions in separate functions/methods etc. but the data still is an unstructured mess: there are arrays, data structures, boolean flags, temporary buffers etc. all over the place. OOP allows the structuring of both the functions as well as the data. An easy 'trick' to accomplish this structuring is: write down the/a solution to a problem in a simple natural language (e.g. English); mark the nouns in your story; they are the classes/objects of your program to be. Next mark the verbs; they are the methods that belong to the nouns (classes). Avoid the word 'it' in your story, because that 'it' is an unknown class; make 'it' a noun.

    If the resulting classes become a mess, rewrite your story in other words. Any noun that means something to you (related to the problem and the solution) should be the name of a class. The same holds for th verbs/method names. Finding the 'optimal' structuring of classes and their methods is more or less and art form; you need to practise.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    arnor is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Re: Learning Java - Switch from structured programming to object oriented programming

    JosAH this is a valuable advice. Thanks to this approach I have a few ideas how to name packages, classes and methods.

    However I am curious how other software-developers more experienced than me in OOP field would name packages, classes and methods (when creating earlier specified Car Rental Software)?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Learning Java - Switch from structured programming to object oriented programming

    Well, Java has a naming convention for classes, methods, etc; google is your friend here.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Object Oriented Programming
    By TylerJoeWatts in forum New To Java
    Replies: 11
    Last Post: 11-27-2013, 10:32 AM
  2. Replies: 0
    Last Post: 11-19-2013, 05:02 PM
  3. Replies: 0
    Last Post: 12-28-2012, 03:01 PM
  4. help for Object Oriented Programming RMI
    By clapton in forum New To Java
    Replies: 0
    Last Post: 03-20-2012, 06:42 PM
  5. Replies: 1
    Last Post: 08-04-2011, 09:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •