riswux / VisualNovel-1

0 stars 0 forks source link

Feature Envy #7

Open riswux opened 1 year ago

riswux commented 1 year ago
Example 1

```kotlin fun selectedPosition(position: String){ val mainActivity = MainActivity() when(position){ // ... "goTitleScreen" -> mainActivity.goToTitleScreen() } // ... } ``` ### Description of the deficiency Feature Envy occurs when one class excessively relies on the methods or properties of another class, indicating that the code is more interested in the data of another class than its own data. In this case, the `selectedPosition()` method creates an instance of the `MainActivity` class (`val mainActivity = MainActivity()`) and calls its `goToTitleScreen()` method. ### Why is this code bad? What principles does it violate? What can the existence of such code lead to? Violation of Single Responsibility Principle (SRP), `The selectedPosition()` method in the Story class is responsible for handling the logic related to the selected position. Violation of Law of Demeter (LoD): The code violates the LoD by directly accessing the `goToTitleScreen()` method of `MainActivity`. The existence of this code can lead to decreased maintainability, as the tight coupling between the Story and MainActivity classes makes the code harder to understand, modify, and maintain. This flaw might appear if there is a lack of proper separation of concerns and a clear understanding of the responsibilities of each class.

LidiaIvanova commented 1 year ago

It's very strange code for Android development. 0,8