Amaliy ishi-1 Mavzu: Pattern loyihalashda “Factory Method”



Download 17,54 Kb.
Sana31.12.2021
Hajmi17,54 Kb.
#237186
Bog'liq
Новый документ


Muhammad Al-Xorazmiy nomidagi Toshkent

axborot texnologiyalari universiteti



Fan nomi:Dasturiy ta'minot arxitekturasi


Amaliy ishi-1

Mavzu: Pattern loyihalashda “Factory Method”




Guruh: 316-18.

Bajardi:Abdullayev Ilyos.

Toshkent -2021.

Shakl interface
public interface Shape {

void draw();

}

Tortburchak classi
public class Rectangle implements Shape {
@Override

public void draw() {

System.out.println("Shape klasi interfece bup olindi va draw metodidan foydalaniladi Shapeni");

}

}


Kvadrat classi

public class Square implements Shape {
@Override

public void draw() {

System.out.println("Inside Circle::draw() method.");

}

}

Aylana classi

public class Circle implements Shape {
@Override

public void draw() {

System.out.println("Inside Circle::draw() method.");

}

}

Shape factory classini yaratib olamiz. va qatsi shakl ekanligini aniqlimiz
public class ShapeFactory {



// turi shaklidagi ob'ektni olish uchun getShape usulidan foydalaning
public Shape getShape(String shapeType){

if(shapeType == null){

return null;

}

if(shapeType.equalsIgnoreCase("CIRCLE")){

return new Circle();



} else if(shapeType.equalsIgnoreCase("RECTANGLE")){

return new Rectangle();



} else if(shapeType.equalsIgnoreCase("SQUARE")){

return new Square();

}



return null;

}

}

Natija
Inside Circle::draw() method.

Inside Rectangle::draw() method.

Inside Square::draw() method.




MainClassida chaqirib shapni tekshirib kuramiz

public class FactoryPatternDemo {
public static void main(String[] args) {

ShapeFactory shapeFactory = new ShapeFactory();
// Circle ob'ektini oling va uni chizish usulini chaqiring

.

Shape shape1 = shapeFactory.getShape("CIRCLE");
// Circle chizish usulini chaqiring
shape1.draw();
//obyektni boshqattan caqirib rectanglega ulash

Shape shape2 = shapeFactory.getShape("RECTANGLE");
//rectangle metodini chaqirish

shape2.draw();
//turtburchak metodini olib caqirish

Shape shape3 = shapeFactory.getShape("SQUARE");

//turtburchak metodini chaqirish

shape3.draw();

}

}
Download 17,54 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish