0

I have this code of Memory Managment Unit. I made an abstract algorithm Ialgo with 2 Implements. I want to with the MMU class handle different situations. To do this i made a method that get a capacity to make the RAM and get also and Ialgo (1 of the 2 algorithm) but how i can do new for the "algo" member and get the class of the algo i've introduce on the method from the main. Here is the code:

public class MemoryManagmentUnit {
    private Ialgo<Integer> algo;
    private RAM ram;

    public MemoryManagmentUnit(int ramCapacity, Ialgo<Integer> algo){
        this.ram = new RAM(ramCapacity);
        this.algo = new ....?
    }
4

1 回答 1

2

If you hand over the algo parameter in the constructor you won't have to call new to create a new instance. You can use the instance you are injecting.

like so:

 public MemoryManagmentUnit(int ramCapacity, Ialgo<Integer> algo){
    this.ram = new RAM(ramCapacity);
    this.algo = algo;
}

Hope this helps you out.

于 2014-08-16T12:28:29.420 回答