R
R
Romario212018-02-28 10:01:35
Java
Romario21, 2018-02-28 10:01:35

Am I approaching the problem correctly (Java class organization)?

Hello everyone, tell me if I'm approaching the solution of the problem correctly?
There is a left menu that can be FULLSIZE (text + icons + crap) and MINISIZE (icons)
I do have a main class (container) and nested blocks (inner classes), in one of the inner blocks there is a "Resize" button.
Pseudocode:

//Главный класс, контейнер для вложенных блоков
class LeftMenu  {
     Logo logo;
     Menu menu;
     LeftMenu context;
     //Конструктор
      {
       this.context = this;
       setWidth(200px)
      
       logo = new Logo(); //Блок логотипа
       menu = new Menu(); //Само меню
       addComponent(logo,menu)
     }

     void changeSize(){
         logo.changeSize();
         menu.changeSize()
      }

    //Внутренние классы   
    class Logo implement ResizeInterface{
        ......
       Button btnChangeWidth = new Button();
       btnChangeWidth.addOnClickListener(e->context.changeSize())//Метод основного класса
      @override
       void changeSize(){
         setWidth(50px)
       }
    } 

    class Menu implement ResizeInterface{
        ......

      @override
       void changeSize(){
         setWidth(50px)
       }
    } 
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-02-28
@Romario21

Overall, it looks reasonable.

  1. The Logo and Menu classes can be placed in separate files - this will help you not to get lost in the code in the future (when there are a lot of classes and it turns out that there is more than one class in one file, you start to get lost)
  2. Not very clear from the code
    {
           context = this;
           setWidth(200px)
          
           logo = new Logo(); //Блок логотипа
           menu = new Menu(); //Само меню
           addComponent(logo,menu)
         }

    What is context and where is the addComponent, setWidth method declared . If you didn't cut anything out of the code when you posted it here, then it's not clear how it works for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question