Skip to content
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

Cram Additional Properties Into Subclassed VillageState Objects #6

Closed
ThomasThelen opened this issue Sep 9, 2020 · 2 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ThomasThelen
Copy link
Collaborator

ThomasThelen commented Sep 9, 2020

Consider the following class that extends VillageState to include a new variable, aggression.

customState <- R6Class("demographicState",
                          inherit = VillageState,
                          public = list(aggression,
                            initialize = function(aggression=NULL) {
                                          # Let the base class initialize all of the other values
                                          super$initialize()
                                          self$aggression <- aggression
                                                              }
                                        )
                          )

We can create a new state object with

initial_condition <- customState$new()

But. We can't do something like (I'm trying to set the variable in the base class)

initial_condition <- customState$new(carryingCapacity=111)

Most languages have support for passing a variable number of arguments (for example pythons kwargs (actually exactly what I want to do)).

Goal: Use some sort of parameter pack/kwarg feature to pass values into the derived class's initialize method and feed them into the parent class.

https://www.geeksforgeeks.org/packing-and-unpacking-arguments-in-python/

@ThomasThelen ThomasThelen added bug Something isn't working good first issue Good for newcomers labels Sep 9, 2020
@ThomasThelen
Copy link
Collaborator Author

@ThomasThelen
Copy link
Collaborator Author

VillageState is passé. The variables referenced above are slowly moving to other classes and are being managed with manager classes so this should no longer be an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant