새소식

Framework/🍃 Spring

[Spring] 빈(bean)이란? 쉽게 비유로 표현/정식 용어

  • -
728x90


과학자가 로봇을 만든다고 가정한다면, 


철수는 팔을 만들고 
영희는 다리를 만들고
희동이는 몸통을 만든다. 

근데 로봇 1대만 만드는 것이 아니라 1,000대 만들어야 한다..

그럼 철수는 팔만 죽어라 1,000개 만들고
영희는 다리만 죽어라 1,000개 만들고

희동이는 몸통만 죽어라 1,000개 만든다.

그리고 글쓴이가 철수한테는 팔, 영희에게는 다리, 희동이에게는 몸통을 받아서 조립한다.
글쓴이는 조립만 죽어라 한다... 이때 팔, 다리, 몸통 이게 빈이다.



Properties of JavaBeans

A JavaBean is a Java object that satisfies certain programming conventions:

  1. The JavaBean class must implement either Serializable or Externalizable

  2. The JavaBean class must have a no-arg constructor

  3. All JavaBean properties must have public setter and getter methods

  4. All JavaBean instance variables should be private

Example of JavaBeans

@Entity
public class Employee implements Serializable{

   @Id
   private int id;
   private String name;   
   private int salary;  

   public Employee() {}

   public Employee(String name, int salary) {
      this.name = name;
      this.salary = salary;
   }
   public int getId() {
      return id;
   }
   public void setId( int id ) {
      this.id = id;
   }
   public String getName() {
      return name;
   }
   public void setName( String name ) {
      this.name = name;
   }
   public int getSalary() {
      return salary;
   }
   public void setSalary( int salary ) {
      this.salary = salary;
   }
}

감사합니다.


출처 : https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly

출처 : https://okky.kr/article/265869




반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.