简单了解设计模式
设计模式(设计模式概念,来自百度百科)
设计模式(Design Pattern)是一套被反复使用、多数人知晓的、经过分类的、代码设计经验的总结。
使用设计模式的目的:为了代码可重用性、让代码更容易被他人理解、保证代码可靠性。 设计模式使代码编写真正工程化;设计模式是软件工程的基石脉络,如同大厦的结构一样。
package com.example.wangmengjie20190719.base;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.wangmengjie20190719.mvp.IContact;
import com.example.wangmengjie20190719.mvp.persenter.IPersenter;
public abstract class BaseFragment extends Fragment implements IContact.IView {
private boolean isvisiable;
private boolean isinit;
public IPersenter iPersenter;
protected abstract View initlayout(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
protected abstract void initfbc();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
iPersenter = new IPersenter();
iPersenter.OnAttch(this);
return initlayout(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initfbc();
isinit = true;
setload();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
this.isvisiable = isVisibleToUser;
setload();
}
public void setload() {
if (isvisiable && isinit) {
setlazy();
}
}
protected abstract void setlazy();
@Override
public void onDestroy() {
super.onDestroy();
if (iPersenter != null) {
iPersenter.OnDetach();
}
}
;
}