Subclassing an Akka Agent - scala

I would like to create a subclass of akka.agent.Agent. I have tried the following...
import akka.agent.Agent
import markets.tickers.Tick
class TickerAgent(val initialValue: Tick) extends Agent[Tick] {
???
}
...at which point I am prompted to implement the remaining methods of the abstract Agent class. However, I want to keep the default implementations for these methods. It seem from the source that the default implementations are defined in a final, private SecretAgent class inside the Agent companion object.
Is there anyway for me to somehow import or otherwise access the default Agent when implementing a subclass of Agent?

According to my knowledge, there is no other way except implementing the abstract methods defined Agent[T] class. You can call the default methods inside your methods implementation.

Related

Why stateful/stateless widgets extends and doesn't implements?

I have this question for a job interview, and i want to know why the stateful and staless widgets, use extends and why not use implements in Flutter/Dart?
Extends
extends is usually the go-to when you want to make a more specific version of a class.
When you extend a class, you inherit all properties, methods, etc.
If you want to override a method, you prefix the method with #override.
Implements
implements is when you want to make a whole new version of a class but you want to inherit the class type.
When you create a new implementation of a class, you are responsible for supplying everything necessary to make that class function.

Importing a class in matlab

Pretty new to matlab. I want to have a class, which does some calculation. I want to import this class in another class( not instantiate). and use the functions as default functions.
This did not help me much. Can we import a user defined class/functions?
So you have a class calculationClass, and you want to create another class otherClass that can access the calculations provided by calculationClass
One way that works if the calculations are either normal or static methods would be to subclass calculationClass, i.e. start your class definition with
classdef otherClass < calculationClass
[some code here]
end
This way, all methods of calculationClass immediately become available to otherClass. Note that if calculationClass has a nonempty constructor, the subclass will call the constructor as this = this#calculationClass.
If the calculations are static methods only, you can, alternatively, access those calculations as calculationClass.someCalculation(inputArguments), or create a package and use import.

What do parentheses do after a class is called?

I have been trying to make a simple player class that contains all of the important player functions in python. I was just getting into the pygame module, when I noticed a class used parentheses. I took the time to learn what a class does in python, but, couldn't find why parentheses are used after for a class. Here is my main code.
class plr(pygame.sprite.Sprite):
def __init__(self):
plr.__init__(self)
self.image = pygame.Surface((20,20))
self.image.fill(black)
Any explanations?
The parentheses at the end of the line in a class statement surround the base classes of the class you're defining. In the common case, there's just one base class (which may be object if no other base class is needed). In Python 3, you can omit the base class and object will be used by default, but you should always explicitly name object (or some subclass) as a base in Python 2, or you'll get an "old-style" class which is something you probably don't want. (Old style classes are quite thoroughly obsolete and not worth learning about if you're new to Python. They don't exist any more in Python 3.)
Specifying a base class lets your new class inherit methods and other behavior from the base class. Inheritance is a key part of Object Oriented Programming, so you'll probably encounter it quite a bit!
In your specific example, the plr class is inheriting from pygame.sprite.Sprite. That means you can call Sprite methods on instances of plr, and they'll usually just work. You can override some of them, if you want to customize your object's behavior.
I do see an error in your code. The __init__ method you've written will recurse infinitely, since it calls plr.__init__, which is itself! You probably wanted it to call pygame.sprite.Sprite.__init__, which is overriding. You can make that call either with the long name I mentioned above, or by using super (which is nicer). Try:
class plr(pygame.sprite.Sprite):
def __init__(self):
super(plr, self).__init__()
...

Constructor and Unit Testing

I have a class XmlRecord. This class will deal with reading/writing to an xml file. At the moment, I have the following for that class:
class XmlRecord {
private val _file = new File("file.xml")
}
I want this class to somehow create the file if it doesn't exist. I know how to achieve this but I'm unsure how to design it in an Object Orientated way. I think I have two options:
Do I add a code to the constructor (or a call to a private method) that will create this file automatically if it doesn't exist. My problem with this method is that how do I unit test this as this code is effectively private code? Would I have to inject the File dependency so it could be mocked during testing?
Do I get the constructor to return an exception or implement a public method for the class so that the caller can use it to check if a file needs to be created? If so, the caller would then call another public method that would create the file. Again I think I would need to inject the dependency.
I hope that makes sense. I'm just trying to get a better grasp on designing my classes.
The presence of abstractions to accomplish DIP have other design
implications in an Object Oriented program:
All member variables in a class must be interfaces or abstracts.
All concrete class packages must connect only through interface/abstract classes packages.
No class should derive from a concrete class.
No method should override an implemented method.[5]
All variable instantiation requires the implementation of a Creational pattern as the Factory Method or the Factory pattern, or the more complex use of a Dependency Injection framework.
Dependency inversion principle

Eclipse RCP - Custom FilteredPreferenceDialog

I'm trying to implement a custom preference dialog using the FilteredPreferenceDialog class.
The problem that this is an abstract class, but I dont really understand why. It has no abstract methods. I created my own class which extends FilteredPreferenceDialog but then I get the discouraged access warnings. There is another class called WorkbenchPreferenceDialog which also extends FilteredPreferenceDialog, and its also abstract.
Is there a class which is a public not abstract class I can create which has the filtering implementation? The PreferenceDialog class works fine except it doesnt have the filtering mechanism.