Solved

Best way to group common functons in java

Posted on 2011-09-23
5
163 Views
Last Modified: 2013-11-23
Could anybody suggest me a best way to group all common function's in a java project ?
0
Comment
Question by:manugeek
5 Comments
 
LVL 20

Expert Comment

by:a_b
ID: 36585467
Depends on what you mean by common functions.

If they are helper functions you can group them in a singleton utility class.

Else as per the object oriented programming guidelines you add associated functions to an object.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36585485
besides what @a_b has mentioned, if the methods are too similar, you can also refactor and combine then into one. If the difference is minor only, an if condition can be added for the same
0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36597019
Perhaps some context would help.  Do you have some methods (functions) in mind?
0
 

Author Comment

by:manugeek
ID: 36597271
I am writing a testng program and would like to use the following methods fetch(), validate(), createReport() across my testng functions
0
 
LVL 20

Accepted Solution

by:
a_b earned 500 total points
ID: 36597283
Does the class containing these methods have any state?

If not, then create a singleton test utility class and write those methods.
If yes, then you need to follow the OOPs concepts.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now