Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

Exercise 2 (Abstract Factory: GUI based OS)

The purpose of this exercise is to provide a modelisation of a system for creating different components of a graphical user interface (buttons, menu,...) depending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems well suited.

  1. Make the UML diagram of this program. We consider that the buttons have a color, width and height, and menus just wide.

    Make the UML diagram of this program. We consider that the buttons have a color, width and height, and menus just wide.

  2. Write the Java classes d'efinies by the UML diagram.

  3. Add back a new operating system (Mac OS X, for example)

  1. Write the Java classes d'efinies by the UML diagram.
  1. Add back a new operating system (Mac OS X, for example)

Exercise 2 (Abstract Factory: GUI based OS)

The purpose of this exercise is to provide a modelisation of a system for creating different components of a graphical user interface (buttons, menu,...) depending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems well suited.

  1. Make the UML diagram of this program. We consider that the buttons have a color, width and height, and menus just wide.
  1. Write the Java classes d'efinies by the UML diagram.
  1. Add back a new operating system (Mac OS X, for example)

Exercise 2 (Abstract Factory: GUI based OS)

The purpose of this exercise is to provide a modelisation of a system for creating different components of a graphical user interface (buttons, menu,...) depending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems well suited.

  1. Make the UML diagram of this program. We consider that the buttons have a color, width and height, and menus just wide.

  2. Write the Java classes d'efinies by the UML diagram.

  3. Add back a new operating system (Mac OS X, for example)

added 319 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Abstract Factory Patternfactory pattern for a system modelisation

Hi everyone I've just done an exercise on the abstract factory pattern. And and I want someone corrects the exercise by tellingto tell me ifwhether or not I followfollowed the rules of the abstract factory pattern or not.

Here is the exercise:

The purpose of this exercise is to provide a mod'elisationmodelisation of a system for creating different components of a graphical user interface (buttons, menu,...) Dependingdepending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems seems well suited.

Here is The UML:

Here is my code:

The abstract Class ComposantThe abstract class Composant:

package Interfaces;
public abstract class Composant {
protected double largeur ;
protected String color = null;
protected double hauteur ;

public abstract void setColor(String C);
public abstract void setLargeur(double L);
public abstract void setHauteur(double H);

public abstract String getColor();
public abstract double getLargeur();
public abstract double getHauteur();
}

The Boutton class:The Boutton class:

package concreteClasses;
import Interfaces.Composant;
public class Boutton extends Composant{
@Override
public void setColor(String C) {
 color = C;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 hauteur = H;
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 // TODO Auto-generated method stub
 return hauteur;
}
public String toString(){
 return "boutton color ="+color+" boutton largeur ="+largeur+" boutton hauteur ="+hauteur;
}
}

The Menu class:The Menu class:

package concreteClasses;
import Interfaces.Composant;
public class Menu extends Composant{
@Override
public void setColor(String C) {
 color = null;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 return hauteur;
}
public String toString(){
 return "Menu largeur ="+largeur;
}
}

The abstract Class AbstractFatcory:The abstract class AbstractFatcory:

package factoryClasses;
import Interfaces.Composant;
public abstract class AbstractFactory {
public abstract Composant getComposant(String composant);
}

The FactoryComposant Class:The FactoryComposant class:

package factoryClasses;
import concreteClasses.*;
import Interfaces.Composant;
public class FactoryComposant extends AbstractFactory{
@Override
public Composant getComposant(String composant) {
 if(composant.equalsIgnoreCase("Boutton")) return new Boutton();
 else if(composant.equalsIgnoreCase("Menu")) return new Menu();
 return null;
}
}

The Main class:The Main class:

import Interfaces.Composant;
import factoryClasses.*;
public class Main {
public static void main (String[]args){
 
 AbstractFactory factorycomposant = new FactoryComposant();
 Composant compo = factorycomposant.getComposant("Boutton");
 compo.setColor("Red");
 compo.setHauteur(12);
 compo.setLargeur(12);
 System.out.println(compo);
 
 Composant compo2 = factorycomposant.getComposant("Menu");
 compo2.setLargeur(10);
 System.out.println(compo2);
 }
}

Abstract Factory Pattern

Hi everyone I've just done an exercise on the abstract factory pattern. And I want someone corrects the exercise by telling me if I follow the rules of the abstract factory pattern or not.

Here is the exercise:

The purpose of this exercise is to provide a mod'elisation of a system for creating different components of a graphical user interface (buttons, menu,...) Depending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems well suited.

Here is The UML:

Here is my code:

The abstract Class Composant

package Interfaces;
public abstract class Composant {
protected double largeur ;
protected String color = null;
protected double hauteur ;
public abstract void setColor(String C);
public abstract void setLargeur(double L);
public abstract void setHauteur(double H);
public abstract String getColor();
public abstract double getLargeur();
public abstract double getHauteur();
}

The Boutton class:

package concreteClasses;
import Interfaces.Composant;
public class Boutton extends Composant{
@Override
public void setColor(String C) {
 color = C;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 hauteur = H;
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 // TODO Auto-generated method stub
 return hauteur;
}
public String toString(){
 return "boutton color ="+color+" boutton largeur ="+largeur+" boutton hauteur ="+hauteur;
}
}

The Menu class:

package concreteClasses;
import Interfaces.Composant;
public class Menu extends Composant{
@Override
public void setColor(String C) {
 color = null;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 return hauteur;
}
public String toString(){
 return "Menu largeur ="+largeur;
}
}

The abstract Class AbstractFatcory:

package factoryClasses;
import Interfaces.Composant;
public abstract class AbstractFactory {
public abstract Composant getComposant(String composant);
}

The FactoryComposant Class:

package factoryClasses;
import concreteClasses.*;
import Interfaces.Composant;
public class FactoryComposant extends AbstractFactory{
@Override
public Composant getComposant(String composant) {
 if(composant.equalsIgnoreCase("Boutton")) return new Boutton();
 else if(composant.equalsIgnoreCase("Menu")) return new Menu();
 return null;
}
}

The Main class:

import Interfaces.Composant;
import factoryClasses.*;
public class Main {
public static void main (String[]args){
 
 AbstractFactory factorycomposant = new FactoryComposant();
 Composant compo = factorycomposant.getComposant("Boutton");
 compo.setColor("Red");
 compo.setHauteur(12);
 compo.setLargeur(12);
 System.out.println(compo);
 
 Composant compo2 = factorycomposant.getComposant("Menu");
 compo2.setLargeur(10);
 System.out.println(compo2);
 }
}

Abstract factory pattern for a system modelisation

I've just done an exercise on the abstract factory pattern and I want someone to tell me whether or not I followed the rules of the abstract factory pattern.

The purpose of this exercise is to provide a modelisation of a system for creating different components of a graphical user interface (buttons, menu,...) depending on the operating system (Linux, Windows, ...) to which they are intended.

The model must create components without having to know their concrete classes, to be independent of how the components evolve. The Abstract Factory pattern seems well suited.

The abstract class Composant:

package Interfaces;
public abstract class Composant {
protected double largeur ;
protected String color = null;
protected double hauteur ;

public abstract void setColor(String C);
public abstract void setLargeur(double L);
public abstract void setHauteur(double H);

public abstract String getColor();
public abstract double getLargeur();
public abstract double getHauteur();
}

The Boutton class:

package concreteClasses;
import Interfaces.Composant;
public class Boutton extends Composant{
@Override
public void setColor(String C) {
 color = C;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 hauteur = H;
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 // TODO Auto-generated method stub
 return hauteur;
}
public String toString(){
 return "boutton color ="+color+" boutton largeur ="+largeur+" boutton hauteur ="+hauteur;
}
}

The Menu class:

package concreteClasses;
import Interfaces.Composant;
public class Menu extends Composant{
@Override
public void setColor(String C) {
 color = null;
}
@Override
public void setLargeur(double L) {
 largeur = L;
}
@Override
public void setHauteur(double H) {
 
}
@Override
public String getColor() {
 return color;
}
@Override
public double getLargeur() {
 // TODO Auto-generated method stub
 return largeur;
}
@Override
public double getHauteur() {
 return hauteur;
}
public String toString(){
 return "Menu largeur ="+largeur;
}
}

The abstract class AbstractFatcory:

package factoryClasses;
import Interfaces.Composant;
public abstract class AbstractFactory {
public abstract Composant getComposant(String composant);
}

The FactoryComposant class:

package factoryClasses;
import concreteClasses.*;
import Interfaces.Composant;
public class FactoryComposant extends AbstractFactory{
@Override
public Composant getComposant(String composant) {
 if(composant.equalsIgnoreCase("Boutton")) return new Boutton();
 else if(composant.equalsIgnoreCase("Menu")) return new Menu();
 return null;
}
}

The Main class:

import Interfaces.Composant;
import factoryClasses.*;
public class Main {
public static void main (String[]args){
 
 AbstractFactory factorycomposant = new FactoryComposant();
 Composant compo = factorycomposant.getComposant("Boutton");
 compo.setColor("Red");
 compo.setHauteur(12);
 compo.setLargeur(12);
 System.out.println(compo);
 
 Composant compo2 = factorycomposant.getComposant("Menu");
 compo2.setLargeur(10);
 System.out.println(compo2);
 }
}
swapped whiteboard photo with yUML diagram (slightly simplified)
Source Link
Mathieu Guindon
  • 75.5k
  • 18
  • 194
  • 467

enter image description hereyUML diagram depicting the below code

enter image description here

Fix code formatting, mark code as Java.
Source Link
ferada
  • 11.4k
  • 25
  • 65
Loading
Formatted exercise information as a quote and corrected markdown for UML diagram image
Source Link
Loading
Post Migrated Here from stackoverflow.com (revisions)
Source Link
Yassin Ousleyeh
Yassin Ousleyeh
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /