Skip to content

mixin-ization Puppet Abstract Class #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
huan opened this issue Oct 14, 2021 · 1 comment
Closed

mixin-ization Puppet Abstract Class #156

huan opened this issue Oct 14, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@huan
Copy link
Member

huan commented Oct 14, 2021

What is Mixin

Along with traditional OO hierarchies, another popular way of building up classes from reusable components is to build them by combining simpler partial classes. You may be familiar with the idea of mixins or traits for languages like Scala, and the pattern has also reached some popularity in the JavaScript community.
https://www.typescriptlang.org/docs/handbook/mixins.html

Mixin is a great decouple and design pattern to split the puppet class logic into different files.

Wechaty Puppet Mixins

  1. We will have a PuppetSkelton as the base abstract class for all Mixins, it
    1. extends the PuppetEventEmitter for adding the listener typings
    2. has the least components to support other mixins
  2. All functionalities will be added by mixin, for example:
    1. CacheMixin for puppet.cache related codes
    2. WatchdogMixin for puppet.watchdog related codes
    3. MemoryMixin for puppet.memory related codes
    4. MessageMixin, ContactMixin, RoomMixin, etc to add related puppet abstract APIs
  3. All mixins need to implement a start() and stop() and call super.start() and super.stop() inside them, to make sure the start/stop chains can work as expected.

Related issues

@huan huan added the enhancement New feature or request label Oct 14, 2021
huan added a commit that referenced this issue Oct 14, 2021
huan added a commit that referenced this issue Oct 15, 2021
* create PayloadCache class

* init mixins

* add mixin docs

* code clean

* change protected to jsdoc (#155)

* add CacheMixin & WatchdogMin with PuppetSkelton

* add CacheMixin & WatchdogMin with PuppetSkelton

* clean

* follow mixin design (#156)

* Create PuppetError classes (#159)

* split all code into mixins

* fix memory

* fix

* fix memory

* 0.49.4

* clean

* 0.49.5

* rename PuppetError -> GError

* rename PuppetError -> GError

* 0.49.6

* clean code

* 0.49.7
@huan
Copy link
Member Author

huan commented Oct 18, 2021

The Mixins work perfectly and all as expected!

@huan huan closed this as completed Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant