package demo;
//接口分离原则
interface Guest {
// 这里定义浏览者只有查看权限
void see();
}
interface Master {
//这里定义版主有查看和修改权限
void see();
void change();
}
interface Admin {
//这里定义管理员有查看、修改和删除权限
void see();
void change();
void delete();
}
class CreateLimit implements Guest, Master, Admin {
private CreateLimit() {
}
public static Guest user() {
return (Guest) new CreateLimit();
}
public static Master master() {
return (Master) new CreateLimit();
}
public static Admin admin() {
return (Admin) new CreateLimit();
}
public void see() {
System.out.println("你有查看权限");
}
public void change() {
System.out.println("你有修改权限");
}
public void delete() {
System.out.println("你有删除");
}
}
public class Demo_20 {
public static void main(String[] args) {
Guest user = CreateLimit.user();
user.see();
System.out.println("-------------------------");
Master master = CreateLimit.master();
master.see();
master.change();
System.out.println("-------------------------");
Admin admin = CreateLimit.admin();
admin.see();
admin.change();
admin.delete();
}
}
输出结果
你有查看权限
-------------------------
你有查看权限
你有修改权限
-------------------------
你有查看权限
你有修改权限
你有删除