Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 => Is there an efficient patern that forces you to implement wrapper class and matcher.
- When you store most class atributes but have to implement runtime atributes as well.
- case class AnimalAtributeWrapper(size:Int,color:Color) loaded or recieved from external source
- case class AnimalImp(size:Int,color:Color,runtimeAtr:Anyref)
- runtime atribute could be (x:Int,y:Int) coordinate generated by the program or OS specific implemantation of animal.
- Core problem Wrapper -> matcher -> Implemantation, for every new Implementation I have to define wraper and match it to Implemantation.
- 2 => When is it worth it to use lazy vals.
- case class cat (val size:Int, var age:String) {
- //Good if you dont want value to change based on depenecies
- val value:String = s"Original cat atributes: $size,$age"
- //Good if dependencies change
- def method() = s"Current cat atributes: $size,$age"
- //Good if dependencies are immutable?
- //Size never changes so the cast can be done whenever this value is requested
- lazy val sizeTokillorams:Int = size * 10
- }
- 3 => Flyweight design pattern.
- Why not use this for all immutable classes? Memmory leak with infinite object posiibilities?
- Is it possible to find if object reference is used somewhere else (Do manual garbage collect)?
- 4) Difference between Maps:
- If you pass immutable map ref it will never change wile mutable will mutate (shared state)
- //When you pass it around a lot?
- import scala.collection.immutable.Map
- var mapIm = Map()
- mapIm += (key -> value)
- //When private?
- import scala.collection.mutable.Map
- val mapMu = Map.empty[String, Tile]
- mapMu.update(key,value)
- 4 => Defoult parameter value based on other parameters.
- trait Animal {
- def size():Float
- }
- class Cat(val name:String, val size:Float) extends Animal {
- def this(name) = this(name,Cat.genSize(name)
- /*
- Cant do this "aplication does not take paremeters compiler error"
- def this(name) ={
- val size = 5f //cant initalize an intermidiate val
- this(name,size)
- }
- */
- }
- object Cat {
- def genSize(name):Flaot = RandomFloat(seed = name,from = 1f,to = 10f)
- }
- 6) Testing private methods of an abstract class.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement