DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Dependency Injection: RoboGuice vs. ButterKnife

Dependency Injection: RoboGuice vs. ButterKnife

Harsha Vardhan user avatar by
Harsha Vardhan
·
May. 31, 14 · Java Zone · Interview
Like (6)
Save
Tweet
22.88K Views

Join the DZone community and get the full member experience.

Join For Free

Dependency injection

Dependency injection is a software design pattern that implements inversion of control and allows a program design to follow the dependency inversion principle. The term was coined by Martin Fowler - Wikipedia

 Why Dependency injection?

  • Reduction of boilerplate code
  • It promotes reusability, testability and maintainability.

There is any DI for Android? 

Yes, there are many libraries which support injection in android. Listed below are used the most in this space.

  • RoboGuice
  • Android Annotations
  • Dragger
  • ButterKnife
  • Transfuse

Which is the best Dependency Injection Framework?

It’s purely depending on the usage of your project.

For Example:

In android, if I want to avoid the boilerplate code such as injection of views, view holder in adapter and click listeners then the preferred library can be ButterKnife compare to others because remaining all done more than the required. There are tons of features which are not used added in all these libraries.

AndroidAnnotations and ButterKnife does the similar work. RoboGuice, Dagger and Transfuse are in the same category.

We will take one from each, say RoboGuice vs ButterKnife.

RoboGuice
ButterKnife
Minimum Jars required
3 (roboguice-2.0.jar, javax.inject-1.jar and guice-3.0-no_aop.jar)
1 (butterknife-4.0.1.jar)
Should replace Activity?
Yes, Replace Activity with RoboActivity
No Need
ActionBarSherlock
Can be used?
Yes, By adding one more jar (roboguice-sherlock-1.5) to the application and we should replace SherlockActivity to RoboSherlockActivity
Yes, No need of extra jars
Injection for Click Listeners
No
Yes
Performance
There is performance impact as it's done on runtime using reflection
Compile time
Pojo Injection
Yes
No
injection in Fragments
Yes
Yes
Injection in Adapters
No
Yes
Code License
Apache License 2.0
Apache License 2.0
Origin
Rroboguice Link
Butterknife Link

Note: Managing Your App's Memory from developer.android

Avoid dependency injection frameworks

Using a dependency injection framework such as Guice or RoboGuice may be attractive because they can simplify the code you write and provide an adaptive environment that's useful for testing and other configuration changes. 

Be careful about using external libraries

External library code is often not written for mobile environments and can be inefficient when used for work on a mobile client.

Dependency injection

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Most Popular Kubernetes Alternatives and Competitors
  • 10 Steps to Become an Outstanding Java Developer
  • 6 Things Startups Can Do to Avoid Tech Debt
  • How to Submit a Post to DZone

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo