IoC

Product i^ffiAgmA ' JSMféAMMIA Product MAAA TV XiBU ° B MA^A^(Run-time) > Product © inquireOMA

mft ' IoC ° A^gmAKAWmfflfMA

mxx Java ' spwmt

// IDisplay.java package _framework; public interface IDisplay { public void Display ();

// Factory.java package _framework; import _objects.*; import _objects.Integer;

public class Factory { private Document doc; public Document Initialize() { doc = new Document(); doc.Setter(new Integer()); return doc;

Step-2: fernmrnm*

«_objects ^frffi^^Mfflmm : Document fP Integer > S Java M^fif^PT :

// Document.java package _objects; import _framework.*;

public class Document { IDisplay dp;

public void Setter(IDisplay d) { dp = d; } public void Display() { dp.Display(); }

// Integer.java package _objects; import _framework. * ; public class Integer implements IDisplay { int value;

public Integer() { value = 100; } public void Display()

{ System.out.println("Value = " + String. valueOf(value));

^(default package)^M^—{®^ : JMain > S Java fM^fif^PT : Java fM^fif^PT :

// JMain.java import _objects.*; import _framework. * ; public class JMain { public static void main(String[] args) { Factory fa = new Factory(); Document doc = fa.Initialize(); doc.Display();

Step-4:

public class Factory { private Document doc; public Document Initialize() { doc = new Document();

doc.Setter( new Integer()); return doc;

SMTMfM^frM^M(Lifecycle) ' S^WMfr#^(Reference)

lii^^Hg Container = ^ > GM&WftZM ' -WTOMMfrm Setter() SW ' ^^^ Document M Integer MiMfr£ffl^lW#(Depencency) ° it^lS^ '

mmsmftmmmm^m^•mmMisitms^m^ °^n^gmMitmx gmwmisiA® = rsmij m^mmm • ftnmm« - n^»' ^smmiiMf^! :

IMAAWgMtlMMi ' AtMtlAT ° AS^AlWföttMM

ÜE2 ° MAÂâ^MMAtlMAA ' MMŒASfô ° £«J«P A'AAAHffiMA:

// Employee.java package _objects;

public abstract class Employee {

public abstract void SetFee(float basic_fee, float disc); public abstract float GetTotal(); public abstract void display();

// SalesPersonjava package _objects;

public abstract class SalesPerson extends Employee{

protected String name, sex; protected float BasicFee, Discount;

public SalesPerson(String na, String sx) { name = na; sex = sx; } public void SetFee(float basic_fee, float disc){ BasicFee = basic_fee; Discount = disc; } public void display() {

System.0M?.println(name + ", Fee: " + this.GetTotal());

// SalesSecretary.java package _objects;

public class SalesSecretary extends SalesPerson{

public SalesSecretary(String na, String sx) { super(na, sx); } public float GetTotal() {return BasicFee * Discount - 100; }

// JMain.java import _objects.*; public class JMain {

public static void main(String[] args) {

Employee linda = new SalesSecretary("Linda Fan", "Female");

linda.SetFee(2500f, 0.7f);

linda.display();

IfMAMTOfM^^ftMfM'°MM^ftBt'

linda.display();

public void display() {

System.out.println(name + ", Fee: " + this.GetTotal());

public float GetTotal() {

return BasicFee * Discount - 100;

gf^ ' (MMmMMfMg^ SalesPerson m displayOSTO ° GetTotalOm ° imSU SalesSecretary föMffiÄ ' Ä

GetTotalOHÄÄ SalesPerson m dlsplay()®MW¿ = MM» ' S^ffl^m mm» ° ♦

Was this article helpful?

0 0

Post a comment