🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.java
Article #154152

Re: getter, który się wykonuje ale nic nie zwraca

#154152
From: Piotr Rezmer
Date: Wed, 15 Apr 2015 10:15
72 lines
2408 bytes
W dniu 2015-04-15 o 10:42, Jadalbert pisze:

> public abstract class Figura {
>      protected double pole;
>      protected double obwod;
>      public abstract double getSuma3Bokow();
> }
>
> public class Kolo extends Figura {
>      private double pole;
>      private double obwod;
>      public double getSuma2Bokow() {} //patrz poniżej
> }
>
> public class Kwadrat extends Figura {
>      private double pole;
>      private double obwod;
>      private double suma2Bokow;
>      + odpowiednie gettery i settery
> }

Czy możesz wyjaśnić w jakim celu deklarujesz pole i obwód w klasie 
Figura? Czy po to aby cacheować wyliczone wartości?
Zupełnie nie rozumiem też celu deklarowania pole, obwód w klasach Koło i 
Kwadrat. Ja zrobiłbym to prościej:

public abstract class Figura{
	public abstract double GetObwod();
	public abstract double GetPole();
}

public class Kolo extends Figura {
	
	private double radius;
	
	public Figura( double radius ) {
		this.radius = radius
	}

	public double GetObwod() {
		return 2 * Pi * radius;

	}
	public double GetPole() {
		return Pi * radius * radius;
	}

}

public class Kwadrat extends Figura {
	
	private double bok;
	
	public Figura( double bok) {
		this.bok = bok;
	}

	public double GetObwod() {
		return 4 * bok;

	}
	public double GetPole() {
		return bok * bok;
	}

}


-- 
pozdrawiam
Piotr
XLR250&bmw_f650_dakar
Technical Details
Message-ID: <mgldn2$3ge$1@node2.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <d7a3ef5a-592e-4008-9628-d8dfb40110c4@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: Piotr Rezmer <konta@doman.pl>
Newsgroups: pl.comp.lang.java
Subject: Re: getter, który się wykonuje ale nic nie
 zwraca
Date: Wed, 15 Apr 2015 12:15:03 +0200
Organization: ATMAN - ATM S.A.
Lines: 72
Message-ID: <mgldn2$3ge$1@node2.news.atman.pl>
References: <d7a3ef5a-592e-4008-9628-d8dfb40110c4@googlegroups.com>
NNTP-Posting-Host: apn-37-7-4-126.dynamic.gprs.plus.pl
Mime-Version: 1.0
X-Trace: node2.news.atman.pl 1429092898 3598 37.7.4.126 (15 Apr 2015 10:14:58 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Wed, 15 Apr 2015 10:14:58 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
In-Reply-To: <d7a3ef5a-592e-4008-9628-d8dfb40110c4@googlegroups.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit