統一モデリング言語ツールが導入さ:PowerDesignerのを
--->ファイルの新しいモデル - >モデルタイプ - >オブジェクト指向モデル - >クラスdigram
図関係のクラスは次のとおりです。
①相続の一般化を表します。
②関係の実現を達成することである表し
③は、依存の依存関係を表し
この場合、例えばTVとリモコンとの関係であります
④関係(1V1,1VN、NVN)
この関係を表現している:顧客と注文、注文と商品
⑤集約関係
これの例は、選手、チーム、医者
⑥組み合わせの関係
これは選手、頭、脚、足例えば、強い依存性であります
1、クラスとクラス間の継承関係は、特に、キーワードを拡張されたUML図は汎化関係であります
①親
package com.wyq.study;
public class Father{//书写类
//书写属性
private String name;
private int age;
//提供共有的取值赋值方法
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
if(age<0||age>100){
System.out.println("年龄输入有误,请重新输入。");
this.age = 1;
}else{
this.age = age;
}
}
public int getAge(){
return age;
}
//书写无参构造方法
public Father(){
System.out.println("这里是Father的无参的构造方法");
}
public Father(String name,int age){
this.name =name;
this.setAge(age);
System.out.println("这里是Father的带参的构造方法,参数分别是:"+this.name+"\t"+this.getAge());
}
//书写普通方法
public void speak(String language,String work){
System.out.println("这里是父类Father普通方法的测试:其参数为:"+language+"\t"+work+"\t"+this.name+"\t"+this.getAge());
}
}
②サブクラス
package com.wyq.study;
public class Son extends Father{
//属性
private String schoolName;
private int clazz;
//属性私有化
public void setSchoolName(String schoolName){
this.schoolName = schoolName;
}
public String getSchoolName(){
return schoolName;
}
public void setClazz(int clazz){
if(clazz<0||clazz>10){
System.out.println("班级的输入有误。");
this.clazz = 5;
}else
this.clazz = clazz;
}
public int getClazz(){
return clazz;
}
//无参构造
public Son(){
super();
System.out.println("这里是son类的无参构造");
}
public Son(String name,int age,String schoolName,int clazz){
super( name, age);
this.schoolName = schoolName;
this.setClazz(clazz);
System.out.println("这里是son类的带参构造"+"\t"+super.getName()+"\t"+super.getAge()+"\t"+this.getSchoolName()+"\t"+this.schoolName+"\t"+this.getClazz());
}
//书写普通方法
public void study(String course){
System.out.println("正在学习"+course+"\t"+this.schoolName+"\t"+this.getClazz());
}
@Override
public void speak(String language, String work) {
super.speak(language, work);
System.out.println("这里是重写子类Son的测试,参数为:"+super.getName()+"\t"+super.getAge()+"\t"+this.getSchoolName()+"\t"+this.getClazz());
}
}
③テストクラス
package com.wyq.study;
import javax.swing.DebugGraphics;
public class TestSon {
public static void main(String[] args) {
Son s = new Son();//调用子类的无参构造
Son so = new Son("张三",20,"北京大学",2);
so.study("计算机");
System.out.println(so.getName()+"\t"+so.getAge()+"\t"+so.getSchoolName()+"\t"+so.getClazz());
so.speak("python", "码农");
System.out.println("************************");
// Debug;
Father f = new Father("王五",-10);
f.speak("C语言", "工人");
}
}
2、の関係を達成するために:クラスが関係を持つインターフェイスを実装
①インタフェース
package com.wyq.study;
public interface InterF {
public static final String Name = "张三";
public void fun(String grade);
}
②インタフェースクラスの実装
package com.wyq.study;
public class ImplImp implements InterF{
@Override
public void fun(String grade) {
System.out.println("我今年读"+grade);
}
}
③テストクラス
package com.wyq.study;
public class TestIm {
public static void main(String[] args) {
ImplImp im = new ImplImp();
im.fun("三年级");
System.out.println(im.Name);
}
}
3、依存関係:クラス別のクラスを使用して
例えばテレビとリモコン
元のクラスを①
package com.wyq.study;
public class TV {
public void open(){
}
public void close(){
}
public void change(){
}
}
②依存クラスであること
package com.wyq.study;
public class Control {
public void open(TV tv){
tv.open();
}
public void close(){
TV tv = new TV();
tv.close();
}
}
③テストクラス
package com.wyq.study;
public class TestTV {
public static void main(String[] args) {
TV tv = new TV();
Control ct = new Control();
ct.open(tv);
}
}
4、関係
多くの多くの一から一、多くの1つがあり、
例としては、顧客と注文、注文や商品です
リレーションシップは、メンバ変数が行うクラスBクラスコードに反映長期的、強力、です
商品类
public class Product {
}
订单类 --》订单中可以有N多商品
public class Order {
// 在订单中有 N 多商品
// 属性
Product [] pros = new Product[1000];
}
客户--》可以下订单
public class Customer {
private Order order ;
}
図5に示すように、重合の間の関係
この関係は似ています。チーム、選手、チームドクター、コーチ
public class Player { // 球员
}
public class Coach { // 教练
}
public class Doctor { // 队医
}
public class Team {
// 私有属性
private Player p ; // 球员
private Coach c ; // 教练
private Doctor d ; // 队医
}
図6に示すように、関係の組み合わせ
組成の関係は、全体の一部、例えばプレイヤ、頭部、脚部および他のです
public class Head { // 头
}
public class Leg {
}
public class Player { // 球员
private Head head ;
private Leg leg ;
}
8、要約
(1)延びています
(2)実装
パラメーター(3)クラス/ローカル変数のための方法 - >依存
(4)クラスのメンバ変数のための方法 - >(会合、凝集、組成物)