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

[FEATURE] - Refactor EmailMessage Struct to Use Private Fields and Constructor for Enhanced Encapsulation and Data Integrity #5

Closed
JRocabruna opened this issue Jun 4, 2024 · 1 comment · Fixed by #16 or #10
Assignees
Labels
enhancement New feature or request refactoring Code refactoring to improve structure without changing functionality. security Issues related to improving security.

Comments

@JRocabruna
Copy link
Member

Is your feature request related to a problem? Please describe.
Currently, the EmailMessage struct has public fields, which allows external code to modify its state directly. This can lead to issues such as invalid data being set, inconsistent state, and potential security vulnerabilities. For example, email addresses might not be validated, and text inputs might not be sanitized, leading to injection attacks.

Describe the solution you'd like
Refactor the EmailMessage struct to use private fields and provide a constructor and setter methods for field initialization and modification. This will ensure that:

  • All required fields are validated and sanitized at the time of object creation.
  • Modifications to the object's state go through controlled methods that enforce validation and business rules.
  • The internal state of the object remains consistent and protected from external manipulation.

Describe alternatives you've considered
An alternative solution could be to keep the fields public and enforce validation externally, but this approach is error-prone and less secure compared to encapsulating the fields within the struct itself.

Additional context
Encapsulation is a fundamental principle of object-oriented design that helps protect the integrity of an object’s data, hide implementation details, and provide a clear and controlled API. By refactoring the EmailMessage struct to use private fields and a constructor, we can enhance the robustness, security, and maintainability of the code.

Copy link

github-actions bot commented Jul 5, 2024

This issue is stale because it has been open for 30 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring Code refactoring to improve structure without changing functionality. security Issues related to improving security.
Projects
None yet
2 participants