Results 1 to 8 of 8
  1. #1
    rookiecoder is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Object Orientation Help

    Hello,

    I'm attempting to start a new program the "right" way, planning out what is exactly needed, creating the UMLs, and assigning deadlines prior to any coding. So far, I'm stuck on the whole object orientation part.

    The aim for the project is to take predetermined budget data and correspond it to different departments which each have different accounts. It also uses daily revenue intake information to calculate the current budgets compared to the predetermined percentages.

    I'm trying to figure out what classes I should be creating. Here is what I have so far:

    A CheckBook class that contains the main method.
    A Property(property meaning office/site/company) class that contains the read information from the predetermined values document.
    A Department class that creates the different departments.
    An Account class that creates the accounts for the departments.
    An Invoice class that creates the invoices placed into each account (which can also span multiple accounts and departments).
    A DailyRevenue class that allows the input of new revenue.

    A GUI for inputting data regarding invoices and the amounts being placed into the different accounts.
    A GUI to update the DailyRevenue information.

    From my stand point now, it seems like everything could probably be done in GUI classes, but I've done that before and while it works, it ends up being a mess of one or two classes and defeats the purpose of object orientation.

    My question is, how should I be looking at this to get the most organized result for my coding? Should I be using inheritance or abstract classes somewhere? Any advice would be a huge help.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Object Orientation Help

    Have the GUI concentrate on displaying things.
    You might have more than one GUI layer, with a specific screen being the lowest, and some form of manager which deals with the flow between screens.
    You'll need to model that flow.

    You need a business layer that contains the logic for where all this data goes. Parts of this layer will register themselves with the GUI as listeners (at least one interface needed for that). The methods for the listeners will be all about saving changes, or requesting more data. The data request will probably use call backs to return the data to the GUI. That should ensure the GUI and the business code are fairly well detached.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    rookiecoder is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Object Orientation Help

    Thanks Tolls for the quick reply.

    Yes I think this is where my thought process was going, to have a main GUI control the others and to have listeners working throughout to effectly call other methods. I'm not sure I understand where the interface would be used in that regard unfortunately. Do you mind elaborating?

    The business layer as you said should contain the raw data that is being uploaded, updated, and saved. Again, this is where my organization is falling apart. Creating HashSets for the Departments and then HashMaps for the Accounts and Invoices respectfully seem the way to go, but I'm getting lost in the wording. A Property "has a" Department. A Department "has an" Account. An Account "has an" Invoice. An Account, Department, and Property "have a" Budget which is derived from DailyRevenue x Estimated Percentage. Sounds like a large amount of objects that are going to need to be created each time the program boots up.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Object Orientation Help

    SInce you don't seem to have a database as yet, tuck the storing of those things (in Maps, Sets, whatever) behind another set of interfaces. These would be DataAccessObjects (DAO for short). That way you can always replace how you store these things with another implementation, and the business layer simply needs to know how to interact with the things holding all the data.

    For listeners, look up the observer pattern. That's essentially how listeners work. You'll have code along the lines of the following in your subject (the GUI):
    Java Code:
    public void registerAccountChangeListener(AccountChangeListener listener) {
       this.accountChangeListeners.add(listener);
    }
    'accountChangeListeners' would be a List that, when the GUI has one of the Accounts changing, would be iterated over and the relevant method called. Say, addAccount() for a new account, modifyAccount() for changes to an existing one, deleteAccount() for removing one. Note that this is all off the top of my head and I have no idea what your actual requirements are. Don't just copy this without first analysing what you need.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    rookiecoder is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Object Orientation Help

    You've lost me somewhere...

    ...putting the GUI aside for the moment, my goal is to create a heirarchy of sorts:
    Java Code:
    Property I contains:
        Department A contains:
            Account 1 contains:
                Invoice a
                Invoice b
            Account 2
        Department B contains:
            Account 1 contains:
                Invoice b
                Invoice c
            Account 2
    I can sort of see how I would set this up in a database, Property would have a foreign key for Department, Department would have a foreign key for Account, and an Account would have a foreign key for Invoice, but converting that to classes and objects...? Should I be looking at this the same way?

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Object Orientation Help

    In object terms, Property would have a List<Department>, which would have a List<Account>.
    Object Relational Mapping can be a can of worms, because do you really want to load all the Departments and Accounts into your app when you ask for a Property which you might only want to use the name. But that aside, and since this is a learning exercise (?) just load the whole thing to start with. You can look up lazy loading later on (that is loading child data when it's accessed).

    The other option is to simply learn JPA or Hibernate and have it do all the work...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    rookiecoder is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Object Orientation Help

    I just literally realized this after I typed my previous post and quickly set to work on seeing how much of a can of worms it really is. Which might have been slightly easier with Lists, rather than the Sets and Maps I have been using.

    Regardless of the way I've started going about it, this is indeed a learning exercise that I am basing off of my current work, so it is purely experience related to something I use everyday. For now I have a lot to work with, and even more to think about so thank you for all your help. I'll be sure to look up "lazy loading", JPA and Hibernating when I get a chance.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Object Orientation Help

    Both JPA and Hibernate are ORM frameworks for doing just this sort of thing.
    Since this is a learning exercise it's possibly a good idea to attempt it in JDBC first, since that's what Hibernate uses under the hood, and you'll also appreciate some of what Hibernate actually does for you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Object Orientation?
    By atul_kumar2038 in forum New To Java
    Replies: 2
    Last Post: 09-14-2010, 07:21 PM
  2. Object Orientation - Arrays
    By Boysie in forum Jobs Discussion
    Replies: 4
    Last Post: 04-14-2010, 09:32 PM
  3. Multiple columns right to left orientation
    By marjanzfz in forum New To Java
    Replies: 2
    Last Post: 11-12-2009, 03:33 AM
  4. Question on Object Orientation Topic
    By DrMath in forum New To Java
    Replies: 1
    Last Post: 09-29-2009, 07:07 PM
  5. change viewing platform orientation
    By Bit2_Gosu in forum New To Java
    Replies: 1
    Last Post: 02-15-2009, 08:46 AM

Tags for this Thread

Posting Permissions

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