Wednesday, 24 February 2016

introspection in java beans



 In my lat post I have explained what is java bean and it advantages . now look at one of the core concept of java bean "Introspection"

Introspection:-   this the process of analyzing a bean to determine its capabilities. This is an essential feature of the java beans API because it allows another application, such as a design tool, to obtain information about a component.

There are two ways in which the developer of a bean can indicate which of its properties, events, and methods should be exposed.
  1. With the first method, simple naming conventions to infer the introspection mechanisms to infer information about a bean.
  2. In the second way, an additional class that extends the Beaninfo interface is provided that explicitly supplies this information.

Design patterns for Properties:-

A property is a subset of a bean’s state. The values assigned to the properties determine the behavior and appearance of that component. A property is set through a setter method. A property is obtained by a getter method. There are two types of properties: simple and index

1.Simple properties:-

 A simple property has a single value. It can be identified by the following design patterns, where N is the Name of the Property and T is its type.

 Public T getN()  
 Public void setN( T arg)  

A read/write property has both of these methods to access its values. A read-only property has only a get method. A write-only property has only  a set method.

Here are three read/write simple properties along with their getter and setter methods.


 private double depth,height,width;  
 public double getDepth()  
 {  
      reaturn depth;  
 }  
 public void setDepth(double d)  
 {  
      depth=d;  
 }  
 public void getHeight()  
 {  
      return height;  
 }  
 public void setHeight(double h)  
 {  
      height=h;  
 }  
 public double getWidth()  
 {  
      return width;  
 }  
 public void setWidth(double w)  
 {  
      width=w;  
 }  

Indexed properties:-

An indexed property consists of multiple values. It can be identified by the following design patterns, where N is the name of the property and T is its type.

 Public T getN(int index);  
 Public void setN(int index, T value);  
 Public t[] getN();  
 Public void setN( T values[]);  
The following class illustrates the use of indexed properties

 package sunw.demo.indexdemo;  
 public class indexdemo  
 {   
      private final static int n=5;  
      private boolean X[];  
      public indexdemo()  
      {  
           x=new boolean[n];  
           for(int i=0;i<n;i++)  
                X[i]=false;  
      }  
      public boolean getX(int index)  
      {  
           return X[index];  
      }  
      public void setX(int index,boolean value)  
      {  
           X[index]=value;  
      }  
      public void setX(boolean values[])  
      {  
           X=values;  
      }  
 }  

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top