PHP objects and public/private methods
V13
v13 at priest.com
Tue Sep 4 16:18:55 EEST 2007
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);}
};
b) Orismenes fores xreiazetai na xoriseis ta dedomena mias klashs se private
kai protected (p.x. an tithetai thema memory allocation), oste na apofygeis
melontika bugs. Se mikres klaseis den exei idiaiterh shmasia, alla se
megalyteres exei.
Genika, klironomikotita mporeis na xrhsimopoihseis gia diaforoys logoys.
Mporeis p.x. na 'metalakseis' thn arxiki klash, na thn 'employtiseis', na
thn 'ylopoihseis' (an eixe pure virtuals) klp. Otan skopeveis sth 2h
periptosi "xreiazetai" merikes fores na diloseis os private kapoies apo tis
synartiseis h/kai ta dedomena.
> Christos Ricudis
<<V13>>
p.s. <flame> Milame gia C++ panta, giati se otidipote allo to OOP einai apo
pathetic eos apla yparkto </flame>
p.s.2. <flame> Nai, ayto symperilambanei kai thn python kai th ruby kai thn
java.</flame>
p.s.3 Prosopikes apopseis...
More information about the Linux-greek-users
mailing list