0

In our team, we separate the UI logic from the Activity or fragment by creating a new class for the view and let the Activity/Fragment manage the Life Cycle only is this good practice or not?

public abstract class BaseView implements ViewInterface {

    protected View rootView;

    protected Context contextInterface;

    private TextView nameTextView;

    public BaseView(
            Context  contextInterface, 
            LayoutInflater inflater, 
            ViewGroup container
    ) {
        this.contextInterface = contextInterface;
        rootView = inflater.inflate(R.layout.fragment_recycler, container, false);
        nameTextView=rootView.findViewById(R.id.tv_user_name);
    }
}

we decided to that based on this article: https://www.techyourchance.com/activities-android/

0

Seperating the UI from your business logic is a good idea. This allows you some flexibility as business rules and UI framework change at different rates from each other.

...however...

I'd hazard that your link has missed the point of this seperation. It is placing the business logic in the activity, because the activity supplies integration points for the greater system. This still means that your business logic is tied to that specific operating system.

...instead...

Think of the system, and the UI as plugins to your business logic. In this sense your business rules define the services it needs independently of the specific device, framework, or operating system. These services are provided to the Business logic allowing the business logic to control the system. You could write a plugin for the iOS, Windows CE, Red Hat, or any other framework/device/operating system and still use the same business logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.