pub enum DesignPattern {
Singleton {
class: String,
instance_method: String,
instance_field: Option<String>,
private_constructor: bool,
},
Factory {
class: String,
create_methods: Vec<String>,
products: Vec<String>,
is_abstract: bool,
},
Builder {
class: String,
build_method: String,
setters: Vec<String>,
target_type: Option<String>,
},
Adapter {
class: String,
adaptee: String,
target_interface: Option<String>,
},
Decorator {
class: String,
base_interface: String,
component_field: Option<String>,
},
Proxy {
class: String,
subject: String,
proxy_type: Option<String>,
},
Observer {
subject: String,
observers: Vec<String>,
notify_method: String,
subscribe_methods: Vec<String>,
},
Strategy {
interface: String,
implementations: Vec<String>,
context: Option<String>,
},
Command {
interface: String,
commands: Vec<String>,
execute_method: String,
has_undo: bool,
},
DependencyInjection {
class: String,
dependencies: Vec<(String, String)>,
},
Repository {
class: String,
entity_type: Option<String>,
methods: Vec<String>,
},
}Expand description
Detected design pattern with associated metadata.
Variants§
Singleton
Singleton pattern: ensures a class has only one instance.
Heuristics:
- Private/protected constructor
- Static instance field
- Static getter method (getInstance, instance, shared, etc.)
Fields
Factory
Factory pattern: creates objects without specifying exact class.
Heuristics:
- Method returns interface/abstract type
- Creates different concrete types based on input
- Named Factory or has create methods
Fields
Builder
Builder pattern: constructs complex objects step by step.
Heuristics:
- Method chaining (methods return self/Self)
- Has build() or create() method
- Setter-like methods
Fields
Adapter
Adapter pattern: allows incompatible interfaces to work together.
Heuristics:
- Wraps another class
- Implements different interface than wrapped class
- Delegates to wrapped object
Fields
Decorator
Decorator pattern: adds behavior to objects dynamically.
Heuristics:
- Implements same interface as decorated object
- Has reference to decorated object
- Delegates most calls to decorated object
Fields
Proxy
Proxy pattern: provides a surrogate for another object.
Heuristics:
- Same interface as real subject
- Controls access to real subject
- May add lazy loading, access control, logging
Fields
Observer
Observer pattern: defines one-to-many dependency.
Heuristics:
- Has collection of listeners/observers
- Methods like add/remove/notify
- Callback invocation pattern
Fields
Strategy
Strategy pattern: defines family of interchangeable algorithms.
Heuristics:
- Interface with multiple implementations
- Strategy injected via constructor or setter
- Context class uses strategy
Fields
Command
Command pattern: encapsulates request as an object.
Heuristics:
- Has execute() or similar method
- Encapsulates all info needed for action
- Often with undo() support
Fields
DependencyInjection
Dependency Injection pattern (modern alternative to many patterns).
Heuristics:
- Dependencies passed via constructor
- Interface-typed parameters
- No internal instantiation of dependencies
Fields
Repository
Repository pattern: abstracts data access logic.
Heuristics:
- Named *Repository
- Has CRUD-like methods (find, save, delete)
- Works with entity types
Implementations§
Source§impl DesignPattern
impl DesignPattern
Sourcepub fn category(&self) -> PatternCategory
pub fn category(&self) -> PatternCategory
Get the category of this pattern.
Sourcepub fn primary_class(&self) -> &str
pub fn primary_class(&self) -> &str
Get the primary class/type name associated with this pattern.
Trait Implementations§
Source§impl Clone for DesignPattern
impl Clone for DesignPattern
Source§fn clone(&self) -> DesignPattern
fn clone(&self) -> DesignPattern
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DesignPattern
impl Debug for DesignPattern
Source§impl<'de> Deserialize<'de> for DesignPattern
impl<'de> Deserialize<'de> for DesignPattern
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for DesignPattern
impl RefUnwindSafe for DesignPattern
impl Send for DesignPattern
impl Sync for DesignPattern
impl Unpin for DesignPattern
impl UnwindSafe for DesignPattern
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request