fbpx
วิกิพีเดีย

จาวาบีนส์

จาวาบีนส์ (JavaBeans) เป็นคลาสที่เขียนขึ้นด้วยภาษาจาวาอย่างสอดคล้องกับสัญนิยมเฉพาะอย่าง ใช้สำหรับห่อหุ้มอ็อบเจกต์จำนวนมากให้อยู่ในอ็อบเจกต์เดียว (Bean) ซึ่งสามารถส่งเวียนไปรอบๆได้ดีกว่าอ็อบเจกต์เดี่ยวๆ

สัญนิยมของจาวาบีน

Object class ที่จะทำหน้าที่เป็นคลาสจาวาบีนนั้น ต้องเป็นไปตามสัญนิยมเกี่ยวกับการตั้งชื่อเมท็อด การสร้างเมท็อด และพฤติกรรมของเมท็อด สัญนิยมเหล่านี้ทำให้ Object class มีเครื่องมือที่สามารถใช้งาน แทนที่ และติดต่อจาวาบีนได้

สัญนิยมที่จำเป็นได้แก่ :

  • คลาสของต้องมีตัวสร้างที่เป็น Public และ No-argument ซึ่งทำให้สามารถสร้างกรณีตัวอย่างโดยตรวจแก้และกระตุ้นกรอบงานได้โดยง่าย
  • คลาสควรมีคุณสมบัติที่สามารถเข้าถึงได้โดยใช้เมท็อด Get Set และอื่นๆได้ตามสัญนิยมการตั้งชื่อมาตรฐาน ซึ่งทำให้ตรวจสอบและปรับปรุงสถานะของ Bean ตามกรอบงานได้โดยอัตโนมัติ
  • คลาสควรจะทำให้เป็นอนุกรมได้ ซึ่งทำให้โปรแกรมและกรอบงานสามารถบันทึก เก็บ และฟื้นฟูสถานะของ Bean ใน VM และรูปแบบที่เป็นอิสระจากแพลตฟอร์มได้อย่างน่าเชื่อถือ
  • คลาสไม่ควรมีเมท็อด Event-handling ที่จำเป็นใดๆ

ตัวอย่างของจาวาบีนส์

// PersonBean.java public class PersonBean implements java.io.Serializable { private String name; private boolean deceased; // No-arg constructor (takes no arguments). public PersonBean() { } public String getName() { return this.name; } public void setName(String name) { this.name = name; } // Different semantics for a boolean field (is vs. get) public boolean isDeceased() { return this.deceased; } public void setDeceased(boolean deceased) { this.deceased = deceased; } } 
// TestPersonBean.java public class TestPersonBean { public static void main(String[] args) { PersonBean person = new PersonBean(); person.setName("Bob"); person.setDeceased(false); // Output: "Bob [alive]" System.out.print(person.getName()); System.out.println(person.isDeceased() ? " [deceased]" : " [alive]"); } } 

อ้างอิง

  • JavaBean คืออะไร

จาวาบ, นส, javabeans, เป, นคลาสท, เข, ยนข, นด, วยภาษาจาวาอย, างสอดคล, องก, บส, ญน, ยมเฉพาะอย, าง, ใช, สำหร, บห, อห, มอ, อบเจกต, จำนวนมากให, อย, ในอ, อบเจกต, เด, ยว, bean, งสามารถส, งเว, ยนไปรอบๆได, กว, าอ, อบเจกต, เด, ยวๆส, ญน, ยมของจาวาบ, แก, ไขobject, class,. cawabins JavaBeans epnkhlasthiekhiynkhundwyphasacawaxyangsxdkhlxngkbsyniymechphaaxyang ichsahrbhxhumxxbecktcanwnmakihxyuinxxbecktediyw Bean sungsamarthsngewiyniprxbiddikwaxxbecktediywsyniymkhxngcawabin aekikhObject class thicathahnathiepnkhlascawabinnn txngepniptamsyniymekiywkbkartngchuxemthxd karsrangemthxd aelaphvtikrrmkhxngemthxd syniymehlanithaih Object class miekhruxngmuxthisamarthichngan aethnthi aelatidtxcawabinidsyniymthicaepnidaek khlaskhxngtxngmitwsrangthiepn Public aela No argument sungthaihsamarthsrangkrnitwxyangodytrwcaekaelakratunkrxbnganidodyngay khlaskhwrmikhunsmbtithisamarthekhathungidodyichemthxd Get Set aelaxunidtamsyniymkartngchuxmatrthan sungthaihtrwcsxbaelaprbprungsthanakhxng Bean tamkrxbnganidodyxtonmti khlaskhwrcathaihepnxnukrmid sungthaihopraekrmaelakrxbngansamarthbnthuk ekb aelafunfusthanakhxng Bean in VM aelarupaebbthiepnxisracakaephltfxrmidxyangnaechuxthux khlasimkhwrmiemthxd Event handling thicaepnidtwxyangkhxngcawabins aekikh PersonBean java public class PersonBean implements java io Serializable private String name private boolean deceased No arg constructor takes no arguments public PersonBean public String getName return this name public void setName String name this name name Different semantics for a boolean field is vs get public boolean isDeceased return this deceased public void setDeceased boolean deceased this deceased deceased TestPersonBean java public class TestPersonBean public static void main String args PersonBean person new PersonBean person setName Bob person setDeceased false Output Bob alive System out print person getName System out println person isDeceased deceased alive xangxing aekikhJavaBean khuxxairekhathungcak https th wikipedia org w index php title cawabins amp oldid 4710379, wikipedia, วิกิ หนังสือ, หนังสือ, ห้องสมุด,

บทความ

, อ่าน, ดาวน์โหลด, ฟรี, ดาวน์โหลดฟรี, mp3, วิดีโอ, mp4, 3gp, jpg, jpeg, gif, png, รูปภาพ, เพลง, เพลง, หนัง, หนังสือ, เกม, เกม