maul-esel / ssharp

S# is a formal modeling and safety analysis framework for safety-critical systems. It provides a domain specific modeling language and fully automated formal safety analysis tools based on C# and .NET.
http://safetysharp.isse.de/wiki
MIT License
0 stars 1 forks source link

Implementation of capabilities #12

Closed maul-esel closed 8 years ago

maul-esel commented 8 years ago

possible implementation of capabilities:

interface ICapability {
    void Execute(BaseAgent agent);
    bool IsEquivalentTo(ICapability capability);
    CapabilityType Type { get; }
}
interface ICapabilityHandler<T> where T : ICapability {
    void ApplyCapability(T capability);
}

// separate from ICapability, so we don't have to carry the type parameter everywhere
abstract class Capability<T> : ICapability where T : Capability<T> {
    void Execute(BaseAgent agent) {
        var handler = agent as ICapabilityHandler<T>;
        if (handler == null)
            throw new InvalidOperationException();
        handler.ApplyCapability(this);
    }
}
// maybe provide ProduceCapability, ConsumeCapability subclasses (no additional data)
// but not ProcessCapability (will almost always require application-specific data)

class RobotAgent : ICapabilityHandler<Produce>, ICapabilityHandler<Process>, ICapabilityHandler<Consume>
{
    void ApplyCapability(ProduceCapability c) { ... }
    void ApplyCapability(ProcessCapability c) { ... }
    void ApplyCapability(ConsumeCapability c) { ... }
}
enum CapabilityType { Produce, Process, Consume }

Use different capability types to specify invariants (valid tasks etc.)

Use IsEquivalentTo() to distinguish between semantic equality and reference equality of capabilities.

maul-esel commented 8 years ago

IsEquivalentTo() now tracked in #18.