-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seperated into modules and made the strategies generic
- Loading branch information
Showing
7 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:weekplanner/roles/roles.dart'; | ||
|
||
/// Concrete strategy for Citizen role | ||
class CitizenStrategy implements RoleStrategy<CitizenStrategy> { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Citizen role | ||
print("Performing actions as a Citizen"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:weekplanner/roles/roles.dart'; | ||
|
||
/// Concrete strategy for Guardian role | ||
class GuardianStrategy implements RoleStrategy<GuardianStrategy> { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Guardian role | ||
print("Performing actions as a Guardian"); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,33 @@ | ||
// Define a strategy interface | ||
abstract class RoleStrategy { | ||
/// Define a strategy interface | ||
abstract class RoleStrategy<T> { | ||
void performRoleAction(); | ||
} | ||
|
||
// Concrete strategy for Citizen role | ||
class CitizenStrategy implements RoleStrategy { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Citizen role | ||
print("Performing actions as a Citizen"); | ||
} | ||
} | ||
|
||
// Concrete strategy for Trustee role | ||
class TrusteeStrategy implements RoleStrategy { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Trustee role | ||
print("Performing actions as a Trustee"); | ||
} | ||
} | ||
|
||
// Concrete strategy for Guardian role | ||
class GuardianStrategy implements RoleStrategy { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Guardian role | ||
print("Performing actions as a Guardian"); | ||
} | ||
} | ||
|
||
// Concrete strategy for Superuser role | ||
class SuperuserStrategy implements RoleStrategy { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Superuser role | ||
print("Performing actions as a Superuser"); | ||
} | ||
} | ||
// Context class that uses the strategy | ||
class UserContext { | ||
RoleStrategy _roleStrategy; | ||
|
||
|
||
|
||
|
||
|
||
/// Context class that uses the strategy | ||
class UserContext<T extends RoleStrategy<T>> { | ||
RoleStrategy<T> _roleStrategy; | ||
|
||
UserContext(this._roleStrategy); | ||
|
||
void setRoleStrategy(RoleStrategy strategy) { | ||
void setRoleStrategy(RoleStrategy<T> strategy) { | ||
_roleStrategy = strategy; | ||
} | ||
|
||
void executeRoleAction() { | ||
_roleStrategy.performRoleAction(); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:weekplanner/roles/roles.dart'; | ||
|
||
/// Concrete strategy for Superuser role | ||
class SuperuserStrategy implements RoleStrategy<SuperuserStrategy> { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Superuser role | ||
print("Performing actions as a Superuser"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:weekplanner/roles/roles.dart'; | ||
|
||
|
||
/// Concrete strategy for Trustee role | ||
class TrusteeStrategy implements RoleStrategy<TrusteeStrategy> { | ||
@override | ||
void performRoleAction() { | ||
// Implement actions specific to Trustee role | ||
print("Performing actions as a Trustee"); | ||
} | ||
} |