خرید بک لینک

Vote count: 0

I have 3 classes I need to write in Java. They are called Task1, Task2, and Task3, for arguments sake.

The three tasks are exactly the same except that they are different "types" of tasks. So the field type for Task1 will be "Task1" and so on.

Originally I wrote three classes with this one difference. But I think it would be better to write a base class Task and just extend this class in three subclasses [I am obviously somewhat new to Java].

However, I caot figure out how to do this.

My base call looks like this:

package com.scoular.model;

public class TaskBase implements Serializable {

    private static final long serialVersionUID = -5867831497684227875L;

    private String unid;
    private String type;
    private Number order;

    public TaskBase() {
    }

    public void create() {
        try {
            clear();
            newNote = true;
            Session session = Factory.getSession();
            Date date = new Date();
            crtDte = session.createDateTime(date);
            crtUsr = session.getEffectiveUserName();
        } catch (Exception e) {
            XspOpenLogUtil.logError(e);
        }
    }

    public void loadByUnid(String unid) {
...
    }

    public void loadValues(Document doc) {
...
    }

    private void clear() {
...
    }

    public boolean save() {

        boolean tmpSave = true;

            Document doc = null;
            Session session = Factory.getSession();
            Database PCDataDB = session.getDatabase(PCConfig.getpcDataDBpath());

            if (newNote) {
                doc = PCDataDB.createDocument();
                doc.put("order", this.getNextOrder(doc));
            } else {
                doc = PCDataDB.getDocumentByUNID(unid);
            }
            doc.put("title", title);
            doc.put("notes", notes);

            doc.save();

        retu tmpSave;
    }

    // Getters and Setters for common fields

    public String getUnid() {
        retu unid;
    }

    public void setUnid(String unid) {
        this.unid = unid;
    }

    public String getType(String type) {
        retu type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Number getOrder() {
        retu order;
    }

    public void setOrder(Number order) {
        this.order = order;
    }

}

And my super class looks like this:

package com.scoular.model;

import com.scoular.model.TaskBase;

public class Task extends TaskBase implements Serializable {

    private static final long serialVersionUID = -5867831497684227875L;

    // Custom Fields

    public Task() {

        super();
        this.setType("Build");
    }

}

I have cut out some of the extraneous code. In essence I suppose I want an abstract class as I will never instantiate a TaskBase. I understand I could also do this with an implementation but I do not understand that very well.

Any help would be much appreciated.

asked 35 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 18 ارديبهشت 1395 ساعت: 0:21

صفحه بندی