PHP objects and public/private methods

Christos Ricudis ricudis at komodino.itc.auth.gr
Wed Sep 5 10:19:00 EEST 2007


V13 wrote:
> On Tuesday 04 September 2007 13:37, Christos Ricudis wrote:
>> An xreiazesai na dhlwseis mia method san kati pou den einai oute public
>> oute protected, tote apla exeis kanei lan8asmeno OO design. Rethink your
>> objects.
> 
> Oxi akribos:
> 
> a) Paradeigma: Merikes fores o copy constructor kai o operator=() kanoyn 
> paromoia doyleia, opote ftiaxneis mia boithitikh synartisi kai thn kaleis. Oi 
> derived klaseis den exoyn kamia doyleia me ayth th synartisi:
> 
> class A
> {
>   protected:
>     int n;
> 
>   private:
>     void copy(const A &a)  { n=a.n; }
> 
>   public:
>     A(const A &a) { copy(a); }
>     A operator=(const A &a) {copy(a); return(*this);}
> };

Swsto, alla pantelws asxeto. O lytras zhthse prosbash se methods apo 
ORISMENES mono klaseis pou den exoun syggenikh sxesh me thn klash sthn opoia 
briskontai.

Sthn C++ ayto ginetai me thn friend. Sthn Java mporeis na kaneis kati 
paromoio xrhsimopoiwntas Pagkages, alla mou aresei perissotero h proseggish 
ths C++, kyriws epeidh gamaei patokorfa to pure OO montelo,

Proteinw th dhmiourgia epipleon access modifiers :

wife : exei prosbash sta private methods mias class, alla epitrepetai mono 
ena instance. Exei prosbash se ola ta public kai private methods twn parent 
classes poy mporoun na ephreasoyn private attributes twn subclasses twn.

girlfriend : exei prosbash sta private methods ths class A. Oi friend 
classes ths A gnwrizoun thn yparksh ths, alla oxi h wife class. Epitrepontai 
multiple instances.

Se periptwsh pou mia wife class prospa8hsei na prospelasei private methods 
pou thn idia wra einai locked apo mia girlfriend class, prokaleitai fatal 
error.

-- 
Christos Ricudis				ricudis at itc.auth.gr
Systems Administrator				+30-2310-998656
IT Support Center
Aristotle University of Thessaloniki, GREECE




More information about the Linux-greek-users mailing list