Skip to content
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

Add observer pattern. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zoziha
Copy link

@zoziha zoziha commented Aug 15, 2021

  • Add a observer pattern example.

Hope this PR gets your approval, thank you! 😘

Copy link

@DanielEIlie DanielEIlie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello zoziha,

Here are my comments:

  1. More comments needed describing the behavior of the observer and that of the subject.
  2. The code is breaking the Liskov substitution principle: The functions should accept arguments from the base classes.
  3. remove_from_slice and append_slice are utility functions and not necessarily part of the pattern.
  4. The only functions that you need in the abstract interface to illustrate the pattern are: register, deregister, notify and update. Get_Id is a utility function
  5. Put the base classes in one file and the concrete classes in a second file.

Best regards,
Daniel.

@zoziha
Copy link
Author

zoziha commented Aug 16, 2021

Hello Daniel, thanks for your comments!

  1. More comments needed describing the behavior of the observer and that of the subject.

For detailed information, see the reference in the header of every file.

  1. The code is breaking the Liskov substitution principle: The functions should accept arguments from the base classes.

In fact, yes, I can't find a better way to replace the existing writing.
Fortran has many obstacles to the assignment of abstract base classes.
I use type(node) to store class(observer), can you help me try to solve this problem? It may be that I don't have enough programming experience.

  1. remove_from_slice and append_slice are utility functions and not necessarily part of the pattern.

This may also be an obstacle. It is not possible to allocate memory for the same variable multiple times in the same Fortran variable domain. I tried to use these two functions (remove_from_slice and append_slice) to achieve this process.

  1. The only functions that you need in the abstract interface to illustrate the pattern are: register, deregister, notify and update. Get_Id is a utility function

I refer to the Go language code here. It uses this method (get_id) in remove_from_slice like my writing in Fortran. It seems that it needs to be included in the parent class observer, even if it looks like a utility function.

  1. Put the base classes in one file and the concrete classes in a second file.

I continued the writing style of FortranPatterns. Both abstract and concrete classes are placed in a file and a module. This may be a problem, or it may be okay only as an example.

!> Specific objects

type, extends(subject) :: item
type(node), allocatable :: o_list(:)
Copy link
Author

@zoziha zoziha Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use class(observer), allocatable :: o_list(:) here, but this writing method faces some incompatibility issues with the existing grammar of Fortran. I need help! Who can try to solve this problem?

Maybe here (?) my code is breaking the Liskov substitution principle: The functions should accept arguments from the base classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants