basic java design approach for memeber fields -
suppose have low level work java class public method input parameters , other private methods manipulate input data . preferable approach : set input data member fields no need pass between private methods, or pass parameters private methods?
the issue here isn't passing value between private methods, it's how perceive state of object. in other words, make sense instance retain value of parameter passed.
consider, example, builder
class styled after bob builder - fixes many things, once he's done fixing something, it's fixed. it's no longer related bob. on other hand, wears helmet, , takes him wherever goes - part of state:
public class builder { private string name; private helmet helmet; public builder(string name) { this.name = name; } /* helmet methods - helmet data member */ public void wearhelmet(helmet helmet) { this.helmet = helmet; } public void adjusthelmet() { helmet.adjust(); } public void sayhello() { helmet.raise(); } /* can fix it? yes can! doesn't keep afterwards */ public void fix(it it) { straighten(it); paint(it); shine(it); } private void straighen(it it) { // implementation } private void paint(it it) { // implementation } private void shine(it it) { // implementation } }
Comments
Post a Comment