Hi
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.

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.

Or would overloading methods do it.

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

add()
delete()
modify()
//------------------ semester methods ---------

delete(semester){}
//------------------ 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
writeCourse(){}
writeObject(){}
readObject(){}
//...
///
///----------------------sort methods----------------------------------------
sortSemesters()
sortStudents(){}

//etc

}

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.

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.

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

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

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)

(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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.