• Post Reply Bookmark Topic Watch Topic
  • New Topic

Where do put the flow?  RSS feed

 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In object oriented programming we are modeling objects, but simply that won't create a program. Ex, if I want to create a forest simulation, I can create a tree class, lion class, and so on. But these are just objects, where is the "program flow?".
Like, should your program be like a chain reaction? For example dominoes, where you start everything with a single action and they all start falling?

I've made a simple "java helper ". It works, but I'm not sure if i designed it well:

 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program flow starts with the main() method and usually (like you have it) simply launches the program, often by creating an object. From there, you can execute code in the constructor of the object you just created, or create a method in the object you create to run the upper-level processing. For instance:


...or...
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:Ex, if I want to create a forest simulation, I can create a tree class, lion class, and so on. But these are just objects, where is the "program flow?".

Well, a "simulation" usually has a "simulator" - ie, a class that creates "scenarios" for the simulation, often driven by random selections of 'driver' components.

For example, an old classic is a simulation for a bank of lifts (or, for those on the wrong side of the pond, elevators) in an office building. So, in addition to all the classes you might expect like Lift, Building, Passenger etc, you'll have a LiftSimulator class that can supply passengers at random intervals and pre-set thing like how long doors take to open and close, and which floors "express" lifts miss out.

In addition, you may want to measure the "success" (or not) of a particular simulation run - for example, in the case of the LiftSimulator above: passenger throughput and/or average travel time - and this is usually best done with a separate "Metrics" class.

HIH

Winston
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For ecological simulations such as your forest a typical flow of execution would be:

1. Create and initialize the collection of objects representing the ecosystem - trees, soil, fish, whatever - choose a format for initial data that will be easy to edit

2. Advance time a step, for each object interact with the rest of the ecosystem.

3. record / display anything you are tracking in the simulation

4. keep repeating from 2 for the allotted number of steps (time)

5. summarize and gracefully exit

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!