开发者

How do you specify the concrete implementation to be used for a class through Android Resources or Manifest

Suppose I have a Android Application which can have different navigational capabilities based on the conc开发者_开发知识库rete class attached to the application. How to specify the concrete class. Android Resources (R.java) doesnt talk anything about Objects. I do agree that I can have classname as a String attribute and then instantiate through Reflection.. but I am not in favor of that solution.

Which other way I can attach a concrete implementation to the Android Application so that depending on this object, the application can behave differently in different builds.


Consider declaring an interface and have all of the concrete classes implement the interface as plug ins. Then you can either hand code a single line of code such as

Model model= new Model(new MyConcreteClassSpec());

where MyConcreteClassSpec implements IMyModelSpec

Or you can pass an integer value and return a concrete class using a class factory as in:

Model getInstanceModel(int i);

Using an int instead of a enum makes the class factory extensible in the future.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜