Skip to content

0.3 כתיבת API

Ben Brandes edited this page Mar 18, 2019 · 3 revisions

הסבר כללי לגבי כתיבת API

ראשית, התיאור של השיטה/בנאי תמיד יופיעו בשורה ראשונה ולאחר מכן
כאשר אנו כותבים API נשתמש בכמה מילות מפתח
author@ - נכניס פעם אחת בראש הקוד, מציין את שם היוצר
version@ - נכניס פעם אחת בראש הקוד, מציין את הגירסה של הקוד
param@ - נשתמש רק כאשר השיטה שלנו מקבלת פרמטר, כך נוכל להסביר מה המטרה שלו
return@ - נשתמש כאשר אנו כותבים שיטה שהיא לא מהסוג void וכך נסביר מה השיטה מחזירה

מצורפת דוגמה למחלקה עם שיטות ובנאים שכוללת תיעוד API

/**
 * Matala [number of exercise] - [short description of the program]
 *
 * @author [first name] [last name]
 * @version [full date\year only][semester (a\b\c)]
 */

public class SomeClass {
    //Private members, won't show in the API
    private int _a;
    private int _b;
    private int _c;

    /**
     * Constructs and initializes SomeClass's members to 0
     */
    public SomeClass(){
        this._a = this._b = this._c = 0;
    }

    /**
     * Constructs and initializes a SomeClass from the specified a,b,c values
     * @param a a value to be set
     * @param b b value to be set
     * @param c c value to be set
     */
    public SomeClass(int a, int b, int c){
        this._a = a;
        this._b = b;
        this._c = c;
    }

    /**
     * Constructs and initializes a SomeClass from the specified SomeClass.
     * @param other SomeClass to be copied
     */
    public SomeClass(SomeClass other){
        this._a = other._a;
        this._b = other._b;
        this._c = other._c;
    }

    /**
     * Get a value
     */
    public int getA() {
        return _a;
    }

    /**
     * Sets a to a given a
     * @param a value to be set
     */
    public void setA(int a) {
        this._a = a;
    }

    /**
     * Get b value
     */
    public int getB() {
        return _b;
    }

    /**
     * Sets a to a given b
     * @param b value to be set
     */
    public void setB(int b) {
        this._b = b;
    }

    /**
     * Get b value
     */
    public int getC() {
        return _c;
    }

    /**
     * Sets a to a given c
     * @param c value to be set
     */
    public void setC(int c) {
        this._c = c;
    }

    /**
     * Sum up the value of a,b and c
     * @return a + b +c
     */
    public int SumSomeClass(){
        return this._a + this._b + this._c;
    }

    /**
     * return the values of the variables
     * @return A: {value}, B: {value}, C: {value}
     */
    public String toString(){
        return "A: " + this._a + " ,B: " + this._b + " ,C: " + this._c;
    }

    /**
     * Gets a,b and c and add them to the current value
     * @param a value to add a variable
     * @param b value to add b variable
     * @param c value to add c variable
     * @return The new values as string
     */
    public String addValues(int a, int b, int c){
        this._a += a;
        this._b += b;
        this._c += c;

        return this.toString();
    }
}
Clone this wiki locally