Tuesday, 13 June 2017

Where are the most common OOP concepts implemented in java swing jframes?




i currently studying oop in java and i read in a book that java swing jframes are good to understand how oop works in creating gui's in a java program,so where are the following mostly implemeted.
I have done some research and i found some oop concepts implemeting in java



Inheritance - obviously a class need to inherit javax.swing.jframe to use all the methods.



Encapsulation - after creating buttons,panels e.t.c all of them have private access modifiers




So where are




  • Association &Aggregation

  • Polymorphism

  • Abstraction & Interface



utilised?


Answer





  1. Aggregation - JFrame has a JPanel


  2. Composition - JFrame has a JButton
    (composition because JButton cannot exist without a frame)


  3. Polymorphism - Sometimes parameters are passed to methods which are asking in more generic way for example someMethod(Component comp) for comp we can pass a JButton (Because JButton IS-A Component)


  4. Abstraction/Interface sometimes it is needed to implement interfaces and abstract classes, there you have to override all the abstract methods.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...