• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Where do put the flow?

 
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic