What's new

Closed tips po mga master sa java :)

Status
Not open for further replies.

fireclouu

Honorary Poster
Joined
Jun 1, 2014
Posts
438
Solutions
1
Reaction
152
Points
196
hingi po sana ko ng opinion niyo pag nag-eextend ng object, kailan po sa tingin niyo ginagamit mga 'to:

during declaration:

Thread t = new Thread() {
// overrides
}

separated class

public class MyThread extends Thread {
// overrides
}


madalas ko kasi nakikita sa mga fast tutorial 'yung nasa itaas, pero di po ako sure kung kailan ba talaga dapat ginagamit alinman sa dalawa. salamat
 
As a rule of thumb, follow the SOLID principle.

SOLID is an acronym for a set of five software development principles, which if followed, are intended to help developers create flexible and clean code. The five principles are:

  1. The Single Responsibility Principle — Classes should have a single responsibility and thus only a single reason to change.
  2. You do not have permission to view the full content of this post. Log in or register now. — Classes and other entities should be open for extension but closed for modification.
  3. You do not have permission to view the full content of this post. Log in or register now.— Objects should be replaceable by their subtypes.
  4. You do not have permission to view the full content of this post. Log in or register now. — Interfaces should be client specific rather than general.
  5. You do not have permission to view the full content of this post. Log in or register now. — Depend on abstractions rather than concretions.
See You do not have permission to view the full content of this post. Log in or register now.

I wanna put emphasis on SRP (Single Responsibility Principle) in relation to your question. The second form allows you to encapsulate common logic that belongs to your custom MyThread class. But that's really a superficial response. It's like asking is it better to use a screwdriver or knife for sticking holes?
 
Kung gusto mong organized and hindi masyadong magulo sa index mo pwede mong iseparate class. Optional lang naman yun since student ka pa lang pero sa industry advisable ang separate class para mas madaling masundan ng ibang devs.
 
As a rule of thumb, follow the SOLID principle.



I wanna put emphasis on SRP (Single Responsibility Principle) in relation to your question. The second form allows you to encapsulate common logic that belongs to your custom MyThread class. But that's really a superficial response. It's like asking is it better to use a screwdriver or knife for sticking holes?

nice read :) may idea na ko kahit papano
 
Kung gusto mong organized and hindi masyadong magulo sa index mo pwede mong iseparate class. Optional lang naman yun since student ka pa lang pero sa industry advisable ang separate class para mas madaling masundan ng ibang devs.

thanks :)
 
The upper syntax uses anonymous class while the other one is a separate class that extends the Thread Class. You use the upper one if you only need those Thread methods and only concern about it's functionalities. Use the other one if you have some stuff while it needs to incorporate the Thread methods, hence, your class needs to override it's methods. You can simulate this by creating your own Interface then implement its method by using both of these techniques.
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top