I have a class which has alot of tasks related to multiple classes.
the tasks are add, modify ,delete, write on a file and read array from a file.all theses methods operates on objects of other classes as a member variables.
In other words, I have to perform a group of functions on multiple objects ,actually the same functions must be performed on all objects (which are from different classes).
so how can I seperate the tasks?
thank you in advance.

5 Years
Discussion Span
Last Post by creative_m
Featured Replies
  • Maybe those method [B]definitions [/B]belong in the class they apply to, ie in Student there is a [I]delete(Student s)[/I] method, in Course there's [I]delete(Course c[/I]) etc etc. (These should probably be just named [I] delete()[/I] defined as instance methods.) In a typical controller class you will [I]call [/I]those methods, but … Read More


what exactly do you mean?
your explanation makes no sense, it's like saying: I'm writing a method add() or multiply() which has to be able to take a String as well as a Double, and has to be able to be applied to as well a String instance as a Double instance.

do you mean 'this must be able to take parameters of all kinds, as long as they're numerical'?
if so, I think generics is what you mean, but maybe you can try to explain it a bit more clear before I'm saying that's definitely the way to go.

class Controller {
	static ArrayList<Semester> semesterList = new ArrayList<Semester> ();
	static ArrayList<Student>  studentList = new ArrayList<Student> ();
	static ArrayList<AcademicStaff> academicStaffList = new ArrayList<AcademicStaff> ();
	static ArrayList<Enrollment> enrolllementList = new ArrayList<Enrollment> ();
	static ArrayList<Course>  courseList = new ArrayList<Course> ();
	static ArrayList<Object> objects;
//then my methods
//----------------- AcademicStaff methods ------------------------

//------------------ semester methods ---------

//------------------ Student methods ---------

modify(Student s){}
delete (student){}

//------------------ Enrollment methods ---------

modify (Enrollment e){}

//------------------ Course methods ---------

delete (course) {}

//------------------ statistics methods ---------
 static double CourseStatistics (Course course){}

static HashMap<Student, Double> StudentStatistics (Semester semester){}

////-------------------read and write methods----------------------------------
writeStudent(){} //write arrayList of students in a file
///----------------------sort methods----------------------------------------



I should write alot of methods in this class (mentioned above) ,so I want to "splite" this class into pieces to enhance this code so it becomes reusable.

Edited by creative_m: n/a


Why are those arraylists in the same class? How are they related? Are they independent and could be move to their own class with their own editing methods.
Make an abstract class or interface that they extend or implement.


actually, the arraylists can be moved to another class but what about the methods

Edited by creative_m: n/a


just try and rationalize the why. what do you want to achieve by moving them to other classes? every method in each class is reusable, just the scope within can be adjusted by using access modifiers


besides, why do you think methods that in the same class are not reusable?

my class (now) is not reusable because of those non associated method,but the methods themselves are reusable


Maybe those method definitions belong in the class they apply to, ie in Student there is a delete(Student s) method, in Course there's delete(Course c) etc etc. (These should probably be just named delete() defined as instance methods.)
In a typical controller class you will call those methods, but not define them.
If there's significant duplication between the methods in all those classes then consider inheriting them from a common superclass, or using a low-level utility class or classes that they all call on for common functions (eg database updates)

Edited by JamesCherrill: n/a


(These should probably be just named delete() defined as instance methods.)

and the arrayLists should be public and known to every instance of the classes?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.