Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Class/Object/Program Design Conceptualization

    Hello--

    I am new to oo programming and a practice program I'm trying to design/write starts with reading a number of flat files of defined type. In my design, I have a class that covers the content of each type (infoPage). But, do I need create another class to handle determining how many of the files are to be read (this will change each time the program runs)? Conceptually, I'm having trouble understanding how to set this up.

    Suggestions?

    Thanks.

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Class/Object/Program Design Conceptualization

    maybe just create a method to do this, not a complete other class, since both seem to be related to eachother. you could use something like the listFiles() method of the File class to count and/or get the names of the files in a directory...

    so for example:

    Java Code:
    public static void getFileNames() {
                         File nameOfFile = new File("yourdirectorywithfiles").listFiles();
    }
    or do

    Java Code:
    int numberOfFiles = new File("yourdirectorywithfiles").listFiles().length;
    to get the number of files that are in the directory. you can combine the two to get the number of files first then get their names. You could of course skip creating a new method inside your main class and instead just put those statements i listed above directly into your main class, but then you will have to type them out each time you want to call that "function".

    Hope that helps!

  3. #3
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Re: Class/Object/Program Design Conceptualization

    SnakeDoc--

    Thanks. From a code perspective that helps and I'll fit that into a method.

    From a higher level design perspective, I was looking at a class in order to practice a more pure development. I did some more research and I uncovered the Model-View-Controller framework. Using this thinking, I came up with a parserController class that gives me a controller for getting the data from the files (including determining how many files are in the folder, etc). Once the data is parsed from the file, I'll give it to the infoPage object for further processing.

    Does this seem about right?

  4. #4
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Class/Object/Program Design Conceptualization

    Sounds like you are heading in a good direction in my opinion. This will keep the different "functions" (methods) of your classes separated and allows easier reuse of the code. This also leaves the door open to passing the data from your parserController class/methods to another class/method different from your infoPage class later on, if you had a reason to work with that data in a different way for some reason.

    Happy coding! :)

Similar Threads

  1. Replies: 11
    Last Post: 11-30-2011, 05:03 PM
  2. Replies: 3
    Last Post: 05-02-2011, 05:37 AM
  3. Replies: 1
    Last Post: 02-02-2011, 07:11 PM
  4. Program design
    By phil128 in forum New To Java
    Replies: 0
    Last Post: 01-24-2011, 06:48 PM
  5. Replies: 2
    Last Post: 06-22-2010, 05:29 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
  •