C
C
CodeComplete90902019-10-22 00:09:59
Software design
CodeComplete9090, 2019-10-22 00:09:59

How does semantic encapsulation break happen?

I read Code complete (Perfect code) and I cannot understand how encapsulation is broken semantically? Can you give examples of the problem and its solution?
To add a couple of examples from the book:
decide not to call Class A's InitializeOperations() method because Class A's PerformFirstOperation() method calls it automatically;
do not call the database.Connect() method before calling the employee.Retrieve(database ) method, because you know that if there is no connection to the database, the employee.Retrieve() method will establish it;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey P, 2019-10-22
@ruddy22

In short:
Do not make unnecessary movements.
If not so briefly:
You should not make unnecessary movements if they are already implemented somewhere specifically for your case. Speaking of examples from the book, you do not need to "pre-initialize" anything if this initialization or connection to the database is called in the next line. Because it is obvious that it is at least silly to initialize something twice.
Everything is described in detail in the book. Good advice is given, which quite often breaks down on working days. When, working with a hypothetical Vasya's code, you encounter the fact that the PerformFirstOperation() method of Class A does not call the InitializeOperations() method of Class A, and does not even check the "readiness" of any data. So it all depends on the situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question