`

CLASS EVENT

 
阅读更多
*&---------------------------------------------------------------------*
*& Report  ZTCXHTEST_COUNT_EVENT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTCXHTEST_COUNT_EVENT.
*----------------------------------------------------------------------*
*       CLASS vehicle DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS vehicle DEFINITION INHERITING FROM object.
  PUBLIC SECTION.
    EVENTS  too_fast.
    METHODS: show_speed, accelerate.
  PROTECTED SECTION.
    DATA  speed TYPE i.
ENDCLASS.                    "vehicle DEFINITION

*----------------------------------------------------------------------*
*       CLASS vehicle IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS vehicle IMPLEMENTATION.
  METHOD accelerate.
    speed = speed + 1.
    IF speed > 5.
      RAISE EVENT too_fast.
      speed = 5.
    ENDIF.
  ENDMETHOD.                    "accelerate
  METHOD  show_speed.
    WRITE:  / 'speed', speed.
  ENDMETHOD.                    "show_speed
ENDCLASS.                    "vehicle IMPLEMENTATION

*----------------------------------------------------------------------*
*       CLASS handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS handler DEFINITION.
  PUBLIC SECTION.
    METHODS handle_event FOR EVENT too_fast OF  vehicle.
ENDCLASS.                    "handler DEFINITION

*----------------------------------------------------------------------*
*       CLASS handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS handler IMPLEMENTATION.
  METHOD handle_event.
    WRITE:  / 'speed can not too fast.'.
    "speed = 10.
  ENDMETHOD.                    "handle_event
ENDCLASS.                    "handler IMPLEMENTATION

DATA: vehical_ref TYPE REF TO vehicle,
      handler_ref TYPE REF TO handler.

START-OF-SELECTION.
  CREATE OBJECT:  vehical_ref,handler_ref.
  SET HANDLER handler_ref->handle_event FOR ALL INSTANCES.
  DO 11 TIMES.
    CALL METHOD:  vehical_ref->accelerate,
                  vehical_ref->show_speed.
  ENDDO.


  • 大小: 4.7 KB
分享到:
评论

相关推荐

    class-event:此类的对象可以触发事件,其他对象可以绑定到这些事件

    ClassEvent提供了两种方法, on和off分别用于添加和删除侦听器。 语法是: srcObj . on ( "eventName" , [ targetObj , ] [ callback ] ) ; srcObj . off ( "eventName" , [ targetObj , ] [ callback ] ) ; 每...

    C++Event机制的简单实现

    class EventManager { public: // 注册事件监听器 void RegisterListener(const std::string& eventType, std::function(const Event&)> listener) { listeners_[eventType].push_back(listener); } // 触发...

    Ext official doc - class-event-observer

    `class-event-observer`是Ext框架中的一个核心概念,它涉及到事件监听和处理机制,这对于理解和使用Ext进行事件驱动编程至关重要。 在Ext中,类事件观察者(Class Event Observer)是一种设计模式,它允许类级别的...

    Laravel开发-event-sourcing

    class EventStore { public function save(Event $event) { // 将事件保存到数据库或其它存储媒介 } public function replay() { // 重新播放所有事件,以恢复应用状态 } } ``` ### 3. 应用状态重建 通过...

    Event Bus C# 事件总线

    public class EventSubscriber { private readonly EventBus _eventBus; public EventSubscriber(EventBus eventBus) { _eventBus = eventBus; _eventBus.Subscribe((@event) => Console.WriteLine("接收到...

    C++ 课后题 Event类

    class Event { public: Event(EventType type, EventSource source) : eventType(type), eventSource(source) {} EventType getType() const { return eventType; } EventSource getSource() const { return ...

    python事件驱动event实现详解.docx

    class EventManager: def __init__(self): # 事件队列 self.__eventQueue = Queue() # 事件管理器开关 self.__active = False # 事件处理线程 self.__thread = Thread(target=self.__Run) self.count = 0 #...

    c++实现的对象事件驱动机制

    class ClickEventListener : public EventListener { public: void onEvent(const Event& e) override { if (e.eventType() == CLICK_EVENT) { // 处理点击事件的逻辑 } } }; ``` 在实际应用中,可以创建`...

    Flink双流处理-实时对账实现1

    val stateDesc = new ValueStateDescriptor[Event1]("event1-state", classOf[Event1]) val event1State: ValueState[Event1] = getRuntimeContext.getState(stateDesc) // 处理Event1 override def ...

    Java反射机制实践

    for (Class<? extends EventListener> listenerClass : listenerClasses) { // 创建监听器实例 EventListener listener = listenerClass.getDeclaredConstructor().newInstance(); // 找到并调用onEvent方法 ...

    Android 手写EventBus,ButterKnife=动态代理+注解+反射

    Class<? extends Event> eventType = annotation.eventType(); subscribers.computeIfAbsent(eventType, k -> new ArrayList()).add(subscriber); } } } public void unregister(Subscriber subscriber) { ...

    CtrEvent事件委托学习.rar

    enum class EventType { Clicked, Changed, // ... }; template , typename... Args> using EventCallback = std::function(Args...)>; ``` 2. **事件源**: 创建一个类,作为事件的发布者,它持有事件...

    java CallBack(回调函数)

    public class MyEventHandler implements EventListener { @Override public void onEvent(Event event) { // 处理事件的代码 } } ``` 现在,我们可以创建一个`EventManager`类,它负责调度事件,并接受`Event...

    C++实现C#事件机制

    class EventInterface { public: virtual void Subscribe(void (*callback)(int)) = 0; virtual void Unsubscribe(void (*callback)(int)) = 0; }; ``` 2. 创建一个类,该类实现事件接口并存储函数指针的列表。当...

    Windows程序设计的关键技术.pptx

    ref class EventSource { public: event Del^ E; void fire(int i, float f) { E(i, f); } }; ref class EventReceiver { public: void Handler(int i, float f) { Console::WriteLine("Receive:{0},{1}", i, ...

    java里的自定义实现事件

    public class CustomEventListener implements EventListener { @Override public void handleEvent(Event event) { if (event instanceof CustomEvent) { ((CustomEvent) event).fire(); } } } ``` 5. **...

    SwiftTest.zip

    class EventSender { weak var delegate: MyDelegate? func sendEvent(event: String) { delegate?.didReceiveEvent(event: event) } } ``` 4. 关联代理对象:将实现代理的对象赋值给发送事件对象的代理属性。...

    C#接口与事件编程借鉴.pdf

    public class EventSubscriber { public void Subscribe(EventExample source) { source.CustomEvent += HandleCustomEvent; } public void Unsubscribe(EventExample source) { source.CustomEvent -= ...

    自己做的C#课上用的关于事件继承的讲演PPT

    在这个例子中,`EventClass1`实现了`IEvents`接口,因此它必须声明一个`dele`类型的事件`SomeEvent`。然后,可以通过`RaiseSomeEvent`方法来触发这个事件。 总结起来,事件继承和接口事件的实现提供了在类层次结构...

Global site tag (gtag.js) - Google Analytics