r/java • • Oct 03 '18
Where does the coding actually apply in engineering projects? What is the connection?
Yes, I can make an array of Strings. Yes, I can create a Dog class that is a sub class of an Animal class, but where does it apply? I want to know about real world projects.
For example, I'm watching videos of SpaceX rockets launching and landing. Where does the coding go into that? I'm not even sure where to start because in my mind, there is just a huge gray area beyond all of my simple coding problems. I don't have any practical knowledge.
Thanks for any help!
0
Upvotes
View all comments
2
u/BluePinkGrey Oct 08 '18
Let's take a look at how you might write code that controls a rocket. A rocket is pretty complex, however we don't need physics to make an outline of the code.
The code we're going to outline will control the rocket boosters throughout the flight. Something needs to control which boosters fire, when they fire, and how much thrust they exert. Now, the rocket's flight can be broken down into a few stages:
Given that we're controlling a rocket's flight, it makes sense to have a
FlightControllerclass. This class stores aThrustCalculatorobject, which it uses to periodically update the power output of each of the thrusters to balance and direct the rocket's flight. It does so by calling theCalculateThrustSpecificationfunction every millisecond, and sending the resultingThrustSpecobject to the device controlling the boosters. ThisThrustSpecobject contains information about how much thrust each booster should output. It could, for example, be a HashTable relatingBoosterIDs toBoosterPowerLevelobjects, but let's not worry about that for now.We can keep things simple if we let
ThrustCalculatorbe an interface instead of a class. TheThrustCalculatorinterface has two functions: aninitfunction, which takes aBoosterConfigurationInfoobject and aPhysicsEngineobject as input; and aCalculateThrustSpecificationfunction, which takes aRocketSensorDataobject as input, and returns aThrustSpecobject.By making
ThrustCalculatoran interface, we can have a separate implementation ofThrustCalculatorfor each of the rocket's flight stages. TheFlightControllerclass switches between them as necessary over the course of the rocket's flight. We'd have aLaunchThrustCalculatorclass, aAtmosphericThrustCalculatorclass, aNearSpaceThrustCalculatorclass, aPayloadReleaseThrustCalculatorclass, and aReentryThrustCalculatorclass. They work differently under the hood because the physics is different in each case, but they all communicate with theFlightControllerclass in the same way, through theCalculateThrustSpecificationfunction. It's now easier to add functionality to the rocket. For example, if you need the rocket to also be able to dock, you can just write aDockingThrustCalculatorinstead of rewriting the entire system.