oop - What are the pros and cons of creating a new class? -


this basic question, it's 1 i'm running i'm learning more actionscript 3 in particular. however, first question general: when appropriate put functionality in new class rather new function in same class? according java tutorial, focuses on basic object-oriented principles, class supposed "blueprint of object". understood mean functionality or behavior object use should contained within class. however, according single responsibility principle, each class should have 1 reason change. example, should have 1 class compile report , 1 class print rather single report class.

can guys me understand pros , cons creating new class? costs splitting object multiple classes? there compile-time or performance costs keeping related functionality in same class, or splitting two? there perhaps times want split things out, while might want keep them other times?

as far remember, there isn't big difference between having 1 class can or several classes can same.

it's readability , how can extend code. it's clean code , coupling.

if have class called "printer" don't want have "watercoolersound()" in it. of course more objects have higher chance can run out of memory. not entirely sure whether 1 object functionality or several classes same functionality spread out, takes more memory.

in fact, if need little bag hold on data , not able dance bear @ same time, make sense have 2 separate classes.

it's advisable not think performance before have code. maintainability , understandability viewpoint, of course, smaller classes, smaller methods superior. (see single responsibility principle again :)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -