You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modify the SlowLoadableComponent class to be open for extension, following the Open-closed principle:
In object-oriented programming, the open–closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification";[1] that is, such an entity can allow its behaviour to be extended without modifying its source code.
Specifically:
At the time Meyer was writing, adding fields or functions to a library inevitably required changes to any programs depending on that library.[citation needed] Meyer's proposed solution to this dilemma relied on the notion of object-oriented inheritance (specifically implementation inheritance):
A class is closed, since it may be compiled, stored in a library, baselined, and used by client classes. But it is also open, since any new class may use it as parent, adding new features. When a descendant class is defined, there is no need to change the original or to disturb its clients.[4]
Motivation
Right now SlowLoadableComponent allows a derived class to inherit from it and override how the Load method works:
Which stops us from changing how the Load method works and still be able to wait for the IsLoaded condition to be true.
I propose clock, timeout and Wait become protected.
Example
Let's imagine a component that we now for a fact will only load when the user executes an action (for example, clicking on a button). and we know the component will load slowly. We could skip the first evaluation of IsLoaded:
publicoverrideTLoad(){/*if (this.IsLoaded) //{ // return (T)this; //} //else //{ // this.TryLoad(); //} // we skip this party and go straight to trying to loading the component */this.TryLoad();DateTimeend=this.clock.LaterBy(this.timeout);while(this.clock.IsNowBefore(end)){if(this.IsLoaded){return(T)this;}this.HandleErrors();this.Wait();}if(this.IsLoaded){return(T)this;}else{stringtimeoutMessage=string.Format(CultureInfo.InvariantCulture,"Timed out after {0} seconds.",this.timeout.TotalSeconds);thrownewWebDriverTimeoutException(timeoutMessage);}}
This implementation will not work because we do not have access to clock, timeout and Wait
The same can be achieved by saving a local copy of the fields on a derived class and recreating the Wait method:
🚀 Feature Proposal
Modify the
SlowLoadableComponent
class to be open for extension, following the Open-closed principle:Specifically:
Motivation
Right now
SlowLoadableComponent
allows a derived class to inherit from it and override how theLoad
method works:selenium/dotnet/src/support/UI/SlowLoadableComponent{T}.cs
Lines 72 to 110 in bf2fc56
It also lets derived classes access to SleepInterval:
selenium/dotnet/src/support/UI/SlowLoadableComponent{T}.cs
Lines 63 to 70 in bf2fc56
And IsLoaded:
selenium/dotnet/src/support/UI/LoadableComponent{T}.cs
Lines 51 to 74 in bf2fc56
It does not, however, let us access
clock
andtimeout
fields, and theWait
method:selenium/dotnet/src/support/UI/SlowLoadableComponent{T}.cs
Lines 39 to 40 in bf2fc56
selenium/dotnet/src/support/UI/SlowLoadableComponent{T}.cs
Lines 124 to 127 in bf2fc56
Which stops us from changing how the
Load
method works and still be able to wait for theIsLoaded
condition to be true.I propose
clock
,timeout
andWait
becomeprotected
.Example
Let's imagine a component that we now for a fact will only load when the user executes an action (for example, clicking on a button). and we know the component will load slowly. We could skip the first evaluation of
IsLoaded
:This implementation will not work because we do not have access to
clock
,timeout
andWait
The same can be achieved by saving a local copy of the fields on a derived class and recreating the
Wait
method:But then again, we would be adding "unnecesary" code.
Thank you.
The text was updated successfully, but these errors were encountered: