It's me again!
Today, I would like to write about a fundamantal of my main desing of Project Mercury. This concept is called reusability. If you are a bit experienced in object-oriented designs, you probably have heard this word often.
Let's think about how Orbiter works. In every vessels that we create, there are common things to care about. For example, a big source of headaches is probably saving the scenario. Also, because we are working on rockets, every vessel will need a stage manager that will handle jettisonning rocket parts and show the appropriate meshes. These are only a few examnples, there are much more components that are shared through all vessels of Project Mercury, like animations, panel elements, etc.
The mother class is the Vehicle class. Boat, Car and Aircraft are child classes, they inherit from Vehicle. A Car, a Boat and an Aicraft have the same propreties and methods than a Vehicule. It has a speed, a position, etc. However, the Car has wheels and friction with the road. The Aircraft has friction with the wind and a propeller/jet. A Boat has a propeller diffrent from the Aircraft and friction with water. However, they all have a speed and a position. In this case, Vehicle is a generelized class of Boat, Car and Aircraft.
In our case, the vessel must inherit from VESSEL3. This is simply how Orbiter works. For example, the Atlas class, which is the Atlas version of the Mercury spacecraft, will inherit from VESSEL3. However, I chose to have a generalization between VESSEL3 and Atlas. Why? Because a lot of components will be shared between the Atlas and the Redstone version of the spacecraft. Our diagram looks like this:
This way, the common components will be created in CommonVessel's constructor, and everything else into the respective classes (Atlas or Redstone).
Common components will take a CommonVessel pointer in their constructor. They will only be able to interact other common components. That's logic because they only have the CommonVessel defintion.
Special components will take Atlas or Redstone pointer in their constructor. They will be able to interact with other special components of the respective classes (Atlas or Redstone) and with common components. How will they interact with the common components? That's easy with polymorphism. For example, if a special component takes a Atlas pointer, because Atlas inherits from CommonVessel, it will have all the common components pointer.
That's it! We have reusable code for our project. This will help to ensure proper and faster development.
Thank you for reading!
Today, I would like to write about a fundamantal of my main desing of Project Mercury. This concept is called reusability. If you are a bit experienced in object-oriented designs, you probably have heard this word often.
Why is it important?
Reusability is often an important strategy to use when making designs. However, sometimes, it simply creates headaches more then results. In our case, Project Mercury, reusability is essential in order to produce an effective code.
Let's think about how Orbiter works. In every vessels that we create, there are common things to care about. For example, a big source of headaches is probably saving the scenario. Also, because we are working on rockets, every vessel will need a stage manager that will handle jettisonning rocket parts and show the appropriate meshes. These are only a few examnples, there are much more components that are shared through all vessels of Project Mercury, like animations, panel elements, etc.
How to make our code reusable
To make our code reusable, a feature of object-oriented programming is very handy. It is called polymorphism. "Poly" means "many" and "morph" means "form". Using polymorphism, we will be able to generalize our class. Generalization is often a word used in Unified Modelisation Language, or UML. Here is an example of generalization:
The mother class is the Vehicle class. Boat, Car and Aircraft are child classes, they inherit from Vehicle. A Car, a Boat and an Aicraft have the same propreties and methods than a Vehicule. It has a speed, a position, etc. However, the Car has wheels and friction with the road. The Aircraft has friction with the wind and a propeller/jet. A Boat has a propeller diffrent from the Aircraft and friction with water. However, they all have a speed and a position. In this case, Vehicle is a generelized class of Boat, Car and Aircraft.
In our case, the vessel must inherit from VESSEL3. This is simply how Orbiter works. For example, the Atlas class, which is the Atlas version of the Mercury spacecraft, will inherit from VESSEL3. However, I chose to have a generalization between VESSEL3 and Atlas. Why? Because a lot of components will be shared between the Atlas and the Redstone version of the spacecraft. Our diagram looks like this:
This way, the common components will be created in CommonVessel's constructor, and everything else into the respective classes (Atlas or Redstone).
The components
What about the components that I talked about in my previous entry? We will seperate them in two parts: the common components and the special components.
Common components will take a CommonVessel pointer in their constructor. They will only be able to interact other common components. That's logic because they only have the CommonVessel defintion.
Special components will take Atlas or Redstone pointer in their constructor. They will be able to interact with other special components of the respective classes (Atlas or Redstone) and with common components. How will they interact with the common components? That's easy with polymorphism. For example, if a special component takes a Atlas pointer, because Atlas inherits from CommonVessel, it will have all the common components pointer.
That's it! We have reusable code for our project. This will help to ensure proper and faster development.
Thank you for reading!
