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

а что делать с тем, что я хочу assert в конструкторе, чтобы всякие плохие значения не появлялись? #2

Open
DimaTrushin opened this issue Jan 25, 2020 · 0 comments

Comments

@DimaTrushin
Copy link
Collaborator

а что делать с тем, что я хочу assert в конструкторе, чтобы всякие плохие значения не появлялись?

Originally posted by @isaf27 in #1

В дефолтном конструкторе у тебя нет проблем с тем, чем инициализируются твои данные, ты это и так контролируешь, потому проблемы нет. А в не дефолтном конструкторе есть две стратегии:

  1. ты помещаешь assert в тело конструктора и умираешь при неправильных данных.
  2. ты помещаешь в тело конструктора функцию, который чистит данные и строит объект с поддержкой всех инвариантов класса.
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

No branches or pull requests

1 participant