This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // For this example, we are shopping for a Car based on the CarManufacturer | |
| interface CarManufacturer { | |
| } | |
| final class HondaMotor implements CarManufacturer { | |
| } | |
| final class BMWGroup implements CarManufacturer { | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | object Earth { } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Mars { | |
| // Declare private static member variable as `final` to inform the | |
| // compiler that this value will never change. | |
| private static final Mars SINGLETON_INSTANCE = new Mars(); | |
| // Make the constructor private to avoid any other instances of this class | |
| // From being created. | |
| private Mars() { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | class Earth { | |
| // Have a private and static member variable to hold the singleton instance. | |
| private static Earth SINGLETON_INSTANCE; | |
| // Make the constructor private to avoid any other instances of this class | |
| // From being created. | |
| private Earth() { | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | fun ConstraintLayout.updateConstraints(instructions: List<ConstraintInstructions>) { | |
| ConstraintSet().also { | |
| it.clone(this) | |
| for (instruction in instructions) { | |
| if (instruction is ConnectConstraint) it.connect(instruction.startID, instruction.startSide, instruction.endID, instruction.endSide) | |
| if (instruction is DisconnectConstraint) it.clear(instruction.startID, instruction.startSide) | |
| } | |
| it.applyTo(this) | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ConnectConstraint(R.id.image, ConstraintSet.Top, R.id.title, ConstraintSet.BOTTOM) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <TextView | |
| android:id="@+id/title" | |
| android:layout_height="wrap_content" | |
| android:layout_width="wrap_content" | |
| app:layout_constraintEnd_toEndOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent"/> | |
| <ImageView | |
| android:id="@+id/image" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | interface ConstraintInstructions | |
| data class ConnectConstraint(val startID: Int, val startSide: Int, val endID: Int, val endSide: Int) : ConstraintInstructions | |
| data class DisconnectConstraint(val startID: Int, val startSide: Int) : ConstraintInstructions | 
NewerOlder