Skip to content

Instantly share code, notes, and snippets.

@HW-Lee
Last active November 25, 2021 13:47
Show Gist options
  • Save HW-Lee/80116e671c27e5488be26031d2419391 to your computer and use it in GitHub Desktop.
Save HW-Lee/80116e671c27e5488be26031d2419391 to your computer and use it in GitHub Desktop.
TaiwanConsensus
public abstract class People {
abstract public String getNationality();
abstract public String getAdjective();
public interface Thinkable {
String getOppose();
String getConsensus();
}
public String getDeclaration() {
StringBuilder builder = new StringBuilder();
if (!(this instanceof Thinkable))
return builder.append("I'm a person from ").append(getNationality()).append(". ^^").toString();
return builder.append("The ").append(getAdjective())
.append(" will never accept ").append(((Thinkable) this).getOppose()).append(". Instead, ")
.append("\"").append(((Thinkable) this).getConsensus()).append("\" ")
.append("is the consensus of the vast majority of ").append(getAdjective()).append(".")
.toString();
}
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class TaiwanConsensusActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = findViewById(R.id.text_view);
tv.setText(new ThinkableTaiwanese().getDeclaration());
}
}
public class Taiwanese extends People {
@Override
public String getNationality() {
return "Taiwan";
}
@Override
public String getAdjective() {
return "Taiwanese";
}
}
public class ThinkableTaiwanese extends Taiwanese implements People.Thinkable {
@Override
public String getOppose() {
return "one country, two systems";
}
@Override
public String getConsensus() {
return "Taiwan is a sovereign-independent country";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment