jeudi 24 novembre 2022

physical simulation (OOP): Design and interfaces

For a college project im working on a physical simulation of how different protons react magnetically with each other. I'm looking on how the magnetizations change over time. The goal isn't the physical implementation itself, but creating a design that can be reused in some other context and be improved and expanded later on.

This being my first introduction to OOP, I was quite overwhelmed with all the concepts and principles and different implementations and patterns, you get the idea. What I've done so far is designing my class patterns and associations with each other. So in my example, I've created an physicalObject that consists of other objects. So in my case, I've tried to decouple the magnetic behaviour of a physicalObject into an interface MagneticProperties. The idea being that any object that has magnetic functionality can implement that interface.

I'm sure there is a lot to improve since I'm getting different ideas with any new concepts I read into. Apart from how my physicalObject is designed, what I'm wondering right now is how i would connect all of my created physicalObjects.

In my simulation, I need to calculate the magneticfield acting on a physObject. For this calculation however, I need the information on all the physObjects created. Also each timestep I need to calculate how the magnetization of one physObject changes using the BlochEquations.

My idea right now is to kind of create an object that stores all phyObjects and registers any change of their properties. Depending on which property changes, this objects would trigger different calculations. I have no idea though, how i should design this structure or if i should even do it this way. I'm sure there is a better way to design this. I have read into the observer pattern and thought this would be a good design, but im not sure anymore. I feel like this would make things more complex and i guess having many objects, it would make things difficult and not really reusable.

I'm not sure why I cant find a solution to my problem. I figured this kind of pattern or structure has to exist somewhere in like autonomous driving or in other scenarious where there is an object registering other objects and their change. But im struggling looking for answers. So here I am, directing this question to the community. Maybe anyone here can give an insight to what im missing :)

class diagram

Aucun commentaire:

Enregistrer un commentaire