matlab-decorators

버전 0.0.1 (11.1 KB) 작성자: Antonio Hortal
Decorator attribute for Matlab classes
다운로드 수: 7
업데이트 날짜: 2023/9/4

matlab-decorators View matlab-decorators on File Exchange

Decorator attribute for Matlab classes

When a class inherits from Decoratable, it can define decorators in the "SetDecorator" and "GetDecorator" attribute for its properties; or the "Decorator" attribute for its methods. Decorators take a function (a getter, setter or method of the class) and return another function that will be executed instead of the original one. Output functions must have the same signature (nargin and nargout) as the original function.

  • Decorators must start with the function handle symbol: "@"
  • Decorators must accept at least 2 input arguments: the function they wrap (setter, getter or method) and the context struct
  • Additional input arguments are passed in the attribute between brackets
  • Many decorators can be used by using a cell array {}. In that case, decorators are called from left to right: {@decorator1, @decorator2} == @decorator1(@decorator2(...))

Example:

classdef DecoratableSubclass < Decoratable
    properties (Description = "SetDecorator = @decorator.count")
        Property1
        Property2
    end
    properties (Description = "GetDecorator = @decorator.trace")
        Property3
    end
    methods (Description = "Decorator = {@decorator.nshot, @decorator.delay(3)}")
        function threeSecondDelayMethod(~)
        end
    end
end

This class defines a set decorator for Property1 and Property2, a get decorator for Property3, and two method decorators for its method. To understand the behaviour of the decorated class properties and methods, see the decorators defined in the "/+decorator" package

License

MIT

Disclaimer

Don't use it for production :) This is something I did for fun and to see what can be achieved through Matlabs OOP metaprogramming features

인용 양식

Antonio Hortal (2024). matlab-decorators (https://github.com/LordTumnus/matlab-decorators/releases/tag/0.0.1), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2022b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
태그 태그 추가

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
0.0.1

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.