-
Notifications
You must be signed in to change notification settings - Fork 9
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
sloppy TTypes #213
Comments
Same problem with |
Yes, we should introduce TTypes for the supertypes. @pixelzoom would you like to do so, or shall I give it a try and reassign to you for review? |
@samreid I don't have time, so yes, please address:
|
TBeersLawSolution looks good.
|
... and each of the above Types should access only fields and methods in its associated type, no reaching into supertypes. |
I said:
Indeed, this problem is not isolated to beers-law-lab. Examples: • build-an-atom: TBAAGameChallenge reaches into supertype BAAGameState of BAAGameChallenge, even though TBAAGameState exists. • charges-and-fields: TChargedParticle reaches into supertype ModelElement of ChargedParticle, even though TModelElement exists. |
TPrecipitate calls |
@samreid asked in #213 (comment):
I don't understand what problem you're referring to. This issue deals with serializing fields that aren't defined in the associated type. Referring to inherited fields or methods (which I believe is what you're referring to) in TType function calls seems fine. |
Could this be put on hold until we redesign BLL? |
@zepumph asked:
It could. But I think we're close to closing this issue, dependent on @samreid's answer to #213 (comment). |
After review, it wasn't clear that all of the steps in #213 (comment) were warranted. Instead, I started with the specific recommendations in #213 (comment) in the preceding commits. @pixelzoom can you please review these commits? |
I introduced TParticles in the preceding commits. I also added Particles.addParticle because it seemed odd to have TParticles calling a method which did not exist on Particles. @pixelzoom can you please take a look? |
I also added a new section to the "how to instrument docs" https://github.com/phetsims/phet-io/blob/master/doc/how-to-instrument-a-phet-simulation-for-phet-io.md#ttypes-should-use-proper-inheritance @pixelzoom can you please take a look? |
@samreid said:
Two problems with Particles/TParticles, both fixed in the above commit: (1) TParticles is calling (2) Particles @samreid please review, close if all looks OK. |
@samreid said:
Looks good, thanks. |
Here is /**
* Removes all particles from the precipitate.
* @public
* @override
*/
removeAllParticles: function() {
if ( this.particles.length > 0 ) {
this.removeParticles( this.particles.length );
}
},
...
/**
* Removes particles from the precipitate.
* @param {number} numberToRemove
* @private
*/
removeParticles: function( numberToRemove ) {
assert && assert( numberToRemove > 0 && numberToRemove <= this.particles.length,
'invalid numberToRemove: ' + numberToRemove );
var removedParticles = this.particles.splice( this.particles.length - numberToRemove, numberToRemove );
assert && assert( removedParticles && removedParticles.length === numberToRemove );
for ( var i = 0; i < removedParticles.length; i++ ) {
removedParticles[ i ].dispose();
}
}, Here is /**
* @public
* @override
*/
removeAllParticles: function() {
var particles = this.particles.slice( 0 );
for ( var i = 0; i < particles.length; i++ ) {
this.removeParticle( particles[ i ] );
}
this.fireChanged();
}
...
// @private
removeParticle: function( particle ) {
this.particles.splice( this.particles.indexOf( particle ), 1 );
particle.dispose();
}, Some questions:
|
@samreid asked:
ShakerParticles calls Precipitate handles the
The implementation of If we want to move more code into Particles, then we should look at applying the Precipitate |
I said:
Decided I'm not going to do this. ShakerParticles and Precipitate are different for good reasons. @samreid There's a fundamental problem in EDIT: Looks like TPrecipitate had this same problem prior to introducing TParticles. That is, its |
@samreid and I worked on the TParticles issue (#213 (comment)) via Slack. We ultimately deleted TParticles and TPrecipitate, and moved all functionality into TShakerParticles. We decided not to save state of individual Precipitate particles, because Precipitate particles are derived from the model. Problems: (1) depending on whether we restored model or view first, we could end up with different behavior; (2) saving/restoring individual particles would require using methods that are private to Precipitate. Nothing else to do here, closing. |
Noted while working on #212
Similar to phetsims/axon#159, I see TTypes that are reaching into arbitrary levels of the concrete type hierarchy to grab fields.
E.g.
TPrecipitateParticle
is forPrecipitateParticle
, a subtype ofSoluteParticle
. Serialization ofTPrecipitateParticle
is reaching intoSoluteParticle
to grabthis.orientation
andthis.locationProperty
. Based on previous discussions, shouldn'tSoluteParticle
fields be handled by a newTSoluteParticle
, whichTPrecipitateParticle
extends?The same problem occurs with
TShakerParticle
, whereShakerParticle
is also a subtype ofSoluteParticle
. Grabbing grabthis.orientation
andthis.locationProperty
is duplicated there. So this seems to be further evidence that there should be aTSoluteParticle
.It also seems like the TType hierarchy should mirror the concrete type hierarchy. Otherwise you break encapsulation, and end up with duplication (like this case).
Please clarify. What are best practices for TType implementation?
EDIT by @samreid: Added whitespace in 1st line to separate onhttp://
The text was updated successfully, but these errors were encountered: