riswux / VisualNovel-1

0 stars 0 forks source link

Divergent Change #5

Open riswux opened 1 year ago

riswux commented 1 year ago
Example 1

```kotlin fun startingPoint(){ val inputEditText = binding.inputName.editText val username = inputEditText?.text.toString() binding.gameTextView.text = "Great, $username! What are we going to do?" binding.inputName.setVisibility(View.INVISIBLE) binding.choiceButton1.setText("Walking") binding.choiceButton2.setText("Hiking") binding.choiceButton3.setText("Go to the field") showAllbuttons() nextPosition1= "walking" nextPosition2= "hiking" nextPosition3= "field" } ``` In this code, the `startingPoint()` method is responsible for multiple unrelated tasks, violating the Single Responsibility Principle. The method is responsible for handling user input, manipulating the visibility of UI elements, and setting text values for buttons.

Example 2

```kotlin fun likecostom(){ binding.gameView.setImageResource(R.drawable.haloween) binding.gameTextView.setText("Thank you! Let’s go to sleep.") binding.gameMC.setVisibility(View.INVISIBLE) binding.inputName.setVisibility(View.INVISIBLE) binding.choiceButton1.setText("Yes, it’s too late...") binding.choiceButton2.setText("") binding.choiceButton3.setText("") binding.choiceButton1.setVisibility(View.VISIBLE) binding.choiceButton2.setVisibility(View.INVISIBLE) binding.choiceButton3.setVisibility(View.INVISIBLE) nextPosition1= "endPoint" nextPosition2= "" nextPosition3= "" } ``` In this code, the `likecostom()` method is responsible for multiple unrelated tasks. It sets the image resource for binding.gameView, updates the text for `binding.gameTextView`, manipulates the visibility of UI elements (`binding.gameMC`, `binding.inputName`, `binding.choiceButton1`, `binding.choiceButton2`, `binding.choiceButton3`), and sets the next positions (`nextPosition1`, `nextPosition2`, `nextPosition3`).

LidiaIvanova commented 1 year ago

Divergent Change smells occur when a single class needs to be edited many times when changes are made in some place. Here you have just violation of single responsibility principle.