1 / 11

การกำหนดการมองเห็น Visibility

การกำหนดการมองเห็น Visibility. วัตถุประสงค์. เพื่อศึกษาชนิดของการมองเห็น ออกแบบเพื่อสร้างการมองเห็น ศึกษาสัญลักษณ์แสดงการมองเห็นใน UML. การมองเห็น (Visibility). ความหมาย Visibility เป็นความสามารถของอ็อบเจกต์ใดๆ ที่มองเห็น หรืออ้างอิงไปยังอ็อบเจกต์อื่นได้

mervin
Download Presentation

การกำหนดการมองเห็น Visibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. การกำหนดการมองเห็นVisibilityการกำหนดการมองเห็นVisibility

  2. วัตถุประสงค์ • เพื่อศึกษาชนิดของการมองเห็น • ออกแบบเพื่อสร้างการมองเห็น • ศึกษาสัญลักษณ์แสดงการมองเห็นใน UML

  3. การมองเห็น(Visibility) • ความหมาย • Visibility เป็นความสามารถของอ็อบเจกต์ใดๆ ที่มองเห็น หรืออ้างอิงไปยังอ็อบเจกต์อื่นได้ • ในอีกแง่หนึ่ง หมายถึงอ็อบเจกต์ของคลาสหนึ่งไปใช้อ็อบเจกต์อื่นให้ทำงานแทน หรือเรียกว่าเกิด dependency

  4. ประเภทการมองเห็น(object A can be see object B) • Attribute visibility • B is an attribute of A. • Parameter visibility • B is a parameter of a method of A. • Local visibility • B is a (non-parameter) local object in a method of A. • Global visibility • B is in some way globally visible. (Larman,2002,pp.280)

  5. Attribute visibility object A object B อ็อบเจกต์ b เป็น attribute ของอ็อบเจกต์ของคลาส A อ็อบเจกต์ของคลาส A มองเห็นอ็อบเจกต์ b getX() b • b is an attribute of A. class A { private B b; public A() { b = new B(); } public void foo() { x = b.getX(); } } class B { private int x; public B() { x=10;} public int getX(){ return x; } } attribute foo() A a = new A(); a.foo(); 1: x:=getX() a:A b:B <<associate>>

  6. Parameter visibility • b is a parameter of a method of A. class B { private int x; public B() { x=10;} public int getX(){ return x; } } class A { public A() { } public void foo(B b) { x = b.getX(); } } parameter B b = new B(); A a = new A(); a.foo(b); foo(b) 1: x:=getX() a:A b:B <<parameter>>

  7. Local visibility • b is a local object within a method of A. (B is not parameter.) class B { private int x; public B() { x=10;} public int getX(){ return x; } } class A { public A() { } public void foo() { B b = new B(); x = b.getX(); } } local A a = new A(); a.foo(); x:= foo() 1: x:=getX() a:A b:B <<local>>

  8. Global visibility • อ็อบเจกต์ b เป็นอ็อบเจกต์ส่วนกลางที่อ็อบเจกต์ A มองเห็นได้ • C++ ทำได้ ด้วยการประกาศตัวแปรส่วนกลาง • Java,C# ทำไม่ได้ แต่ใช้ Singleton pattern แทน

  9. Global visibility Singleton inC# class MyClass1 // statically initialized { private static MyClass1 m_Instance = new MyClass1(); private MyClass1 () {} public static MyClass1 Instance { get { return m_Instance; } } public void DoIt () { Console.WriteLine("Singleton 1"); } } MyClass1m = MyClass1; m.DoIt();

  10. Global visibility Singleton in Java public class MySingleton { private MySingleton(){ }; private static MySingleton m_instance = new MySingleton();} public static MySingletongetInstance() { return m_instance;} public void DoIt () { Console.WriteLine("Singleton in Java"); } } MySingleton m; m = MySingleton.getInstance(); m.DoIt();

  11. สรุป

More Related