What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

tips po mga master sa java :)


fireclouu

Addict
Joined
Jun 1, 2014
Messages
387
Reaction
136
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
 

pixkit

Addict
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?
 
Comment

Fifthford

Leecher
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.
 
Comment

fireclouu

Addict
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
 
Comment

fireclouu

Addict
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 :)
 
Comment

aa1012

Addict
, Last edited:
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.
 
Comment

Like us on facebook

Online statistics

Members online
1,453
Guests online
1,090
Total visitors
2,543

Forum statistics

Threads
885,069
Messages
15,646,106
Members
1,411,350
Top