basic help with a decorator


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: basic help with a decorator

  1. #1
    Join Date
    Sep 2003
    Posts
    1

    Angry basic help with a decorator

    HI there,
    I know little about java and I hope someone can help me,
    My problem is that I must use a decorator pattern and I have a method where I must give a choice in the main method for when a object (in this case an Account) is created it can be of an account object or a TestingAccountable object. The choice must be of the agrument (t) for TestingAccountable.
    I suppose and 'if' statement should be used but I am not sure and if so how excatly should I do it.

    As you can see I am new at this game!!!!1

    Cheers
    Quack

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    I can't quite follow what you want and I don't really see what the Decorator pattern has got to do with this, but I'm assuming you want something like:
    Code:
      class Account {
      }
    
      class TestingAccountable extends Account {
      }
    
      class MyClass { 
         public Account getAccount(int type) {
            Account acc;
            if (type == 0) {
              acc = new Account();
            }
            else {
              acc = new TestingAccountable();
            }
            return acc;
         }
      }
    I'm really guessing here as I couldn't follow what you posted and you didn't post any code.

    (BTW, it seems really strange that you're even thinking about design patterns if you've only just started Java - did your lecturer talk to you about the Decorator pattern?)
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center