Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Need help with design patterns

  • 27-11-2005 10:10PM
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Ok Ive got a project due in tomorrow and I need to know if the below code is in the form of a facade design pattern ?
    It calls one big method in the project 4 class which creates instances of the student and supervisor classes and its own class.


    Is this a facade?

    public class TableFacade
    {
    TableFacade()
    {
    System.out.println("This is the table of projects");
    }

    public Project4 makeTheTable()
    {


    Supervisor5 sup = new Supervisor5();
    Project4 project =new Project4();
    project.readRelevantProjectsFromFile(sup);


    return project;
    }
    }


Comments

  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Im trying to adapt from my project4 class
    is this in the adaptor pattern?



    class AdaptProject
    {
    Project4 project;
    Supervisor5 supervisor;

    void readProjectDetails()
    {

    project.readProjectDetails();


    }

    void readRelevantProjectsFromFile(Supervisor5 v)
    {
    project.readRelevantProjectsFromFile(supervisor);

    }

    String projName()
    {
    return project.projName;
    }
    String projSubject()
    {
    return project.projSubject;
    }
    }


  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    As these are patterns they are open to interpretation but:

    In general the Facade pattern wraps an existing class, and simplifies it. So for something to be a facade pattern it should really wrap only one other class and provide a simpler way of accessing (its over-complex methods)

    The simplest way to think of an Adaptor pattern (at least in java terms) is a new class that wraps another one so that it now implements an interface.

    - There should be an existing interface (that code already uses)
    - There should be an existing class that doesn't implement that interface.
    - The Adaptor class implements both wraps the existing class *AND* implements the interface.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I would say a facade could wrap one or more classes.


Advertisement