-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring base Mapdl class. #2518
Conversation
Moving wrapped functions to MapdlExtended newly created class. Moving properties to the top of _MapdlCore class. Moving functions to Components and mesh_grpc
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2518 +/- ##
==========================================
+ Coverage 82.49% 83.91% +1.42%
==========================================
Files 44 46 +2
Lines 9048 9071 +23
==========================================
+ Hits 7464 7612 +148
+ Misses 1584 1459 -125 |
I do not care about coverage, since it is just a reorg. |
If this is true:
Why do we use that name in the doc in so many places? |
Fair point... because we need to refer to the three interfaces (grpc + console + corba?).... so we have used the parent class (from which the three of them are derived) to refer to it. Probably not the best. We might need a bit of rethinking here. |
This is referring to the numbered list in the description of the PR. I forgot that github turned a hash followed by a number into a hyperlink =/ |
Oh.. Number 3 has "extended" parts ... like functions that wraps functions from parsing:
I figured out it will be better to have been separated |
I generally tend to prefer composition over inheritance - in this case the backend could be a member of the Mapdl class, and then the user-facing class doesn't have to be a base class. And doesn't need a suffixed name like Core or Base |
I dont know enough about composition. But I will investigate that option and come back with an informed opinion. |
The user-facing class will be |
Composition vs Inheritance
Having a read about composition vs inheritance, I end up in this stackoverflow question. So keeping in mind that pymapdl could have implemented the backend through composition as you mention, I believe that given the current relationship between Indeed, you could change it to composition, but I don't see much benefit. I might not being using I must say also, that composition is used extensively in the ExampleGiven my base class: class MapdlBase:
def method1(self, *args, **kwargs):
pass
def set_backend(self, backend):
self.backend = backend Now imagine you want to change the method class MapdlBase:
def method1(self, *args, **kwargs):
return self.backend.method1(*args,**kwargs)
def set_backend(self, backend):
self.backend = backend This forces us to have in the other backends a You could implement a switch in the class MapdlBase:
def method1(self, *args, **kwargs):
if self.backend == "backend1":
return self.backend.method1(*args,**kwargs)
else:
# general implementation
pass But I dont really like to have implementations backend-dependent in the general |
Again...
|
This PR started to close #2082 by making sure I use
wraps
with all the wrapped functions, so I keep the doc string and such.But it quickly growth to a full
mapdl.py
file refactoring. The_MapdlCore
class was getting too long, so I split it in two main files:mapdl_core
with the very base definition.mapdl_expanded
where I expand Mapdl class with new functions or I expand the behaviour of already Mapdl existing.I have also renamed the
_MapdlCore
class toMapdlBase
. I keep this class definition inmapdl.py
file. So it is clear MapdlBase should not be used.New class dependency
Commands
->_MapdlCore
->_MapdlCommandExtended
->_MapdlExtended
->MapdlBase
Commands
class that groups the MAPDL commands as they come from documentation parsing._MapdlCore
added to the above the base methods, like checking type of instance, local, etc._MapdlCommandExtended
: Extend MAPDL commands by wrapping/overwritting MAPDL commands from doc parsing._MapdlExtended
: Add new functions to the above class.MapdlBase
: Just wrap the above with a better name. Allows for more subclassing from_MapdlExtended
.Close #2082