Reputation: 13
I am new to scala and I apologize in advance if the question is stupid. I am browsing through this scala code and I am confused how the following code works
abstract class ClusterSimulatorDesc(val runTime: Double) {
def newSimulator(constantThinkTim: Double,
perTaskThinkTime: Double,
blackListPercent: Double,
schedulerWorkloadsToSweepOver: Map[String, Seq[String]],
workloadToSchedulerMap: Map[String, Seq[String]],
cellStateDesc: CellStateDesc,
workloads: Seq[Workload],
prefillWorkloads: Seq[Workload],
logging: Boolean = false): ClusterSimulator
}
class ClusterSimulator(val cellState: CellState,
val schedulers: Map[String, Scheduler],
val workloadToSchedulerMap: Map[String, Seq[String]],
val workloads: Seq[Workload],
prefillWorkloads: Seq[Workload],
logging: Boolean = false,
monitorUtilization: Boolean = true,
monitoringPeriod: Double = 1.0)
extends Simulator(logging) {
Now if i have a function call like:-
simulatorDesc: ClusterSimulatorDesc
val simulator =
simulatorDesc.newSimulator(constantThinkTime,
perTaskThinkTime,
blackListPercent,
schedulerWorkloadsToSweepOver,
schedulerWorkloadMap,
workloadDesc.cellStateDesc,
workloads,
prefillWorkloads,
logging)
Now the question I have is, what does "ClusterSimulator" at the end of the abstract class declaration does? And, how does the calling of "newSimulator" function happen, considering that its declared in an abstract class?
Upvotes: 0
Views: 87
Reputation: 51271
def newSimulator(....): ClusterSimulator
The method newSimulator()
, when invoked, returns an instance of ClusterSimulator
.
simulatorDesc: ClusterSimulatorDesc
ClusterSimulatorDesc
can't be instantiated because it is abstract, but a class that extends ClusterSimulatorDesc
can be instantiated and an instance of that class is also an instance of ClusterSimulatorDesc
and can invoke its methods.
Upvotes: 2