6
If you have both implicits it's enough just to add context bounds
class Factory {
def of[T: ParquetWriter : JsonWriter](format: Format): FileWriter[T] = {
format match {
case ParquetSpark =>
new ParquetFileWriter[T]("defaultPath")
case Json =>
new JsonFileWriter[T]("defaultPath")
}
}
}
If it's possible that ...
2
A factory delegate could be used at act as a factory for the desired types
public class A {
List<B> _list = new List<B>();
private readonly ILogger logger;
private readonly Func<B1> factory1;
private readonly Func<B2> factory2;
public A(ILogger logger, Func<B1> factory1, Func<B2> factory2) {
...
1
Notice the absence of type parameters here:
public static Operation create(OperationType type) {
// ^ isn't something supposed to be there?
This is known as raw type, and is effectively equivalent with Operation<Object, Object>, however, it can be assigned to Operation<A, B> for any A and B.
What language is pushing you to ...
1
It's because your OperationsFactory returns an Operation rather than a properly genericized Operation<X, Y>, so if you assign it to findOperation of type Operation<InputStream, String>, you get this warning (because the compiler can't assure you assign the right type).
Sadly, you can't add generics to enums (it's on a future Java feature list), ...
1
If I understand your needs correctly,
You want to be able to create HostelReview with a factory that has a relationship with an Hostel
The parameters you pass to factory(App\HostelReview::class, 10)->create([...]) will be handled as specific model properties and overrides the default data in the factory.
What you need is:
Define a default hostel that will ...
1
By passing $count to the factory method $user = factory(User::class, $count)...->create(); you're creating multiple users and the return is a Collection like your Error says.
To assigne the 'Admin' role to each user you have to iterate them
$users = factory(User::class, $count)->state('Admin')->create();
foreach($users as $user)
$user->...
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
factory × 2615angularjs × 532
java × 411
design-patterns × 367
c# × 357
c++ × 277
javascript × 262
php × 188
dependency-injection × 162
factory-pattern × 134
oop × 127
generics × 120
python × 113
service × 92
controller × 91
laravel × 81
spring × 74
.net × 63
constructor × 61
class × 59
inheritance × 58
singleton × 57
unit-testing × 54
templates × 54
ruby-on-rails × 52