From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=BAYES_20,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,b87849933931bc93 X-Google-Attributes: gid109fba,public X-Google-Thread: fac41,b87849933931bc93 X-Google-Attributes: gidfac41,public X-Google-Thread: 1108a1,b87849933931bc93 X-Google-Attributes: gid1108a1,public X-Google-Thread: 114809,b87849933931bc93 X-Google-Attributes: gid114809,public X-Google-Thread: 103376,b87849933931bc93 X-Google-Attributes: gid103376,public From: shang@corp.mot.com (David L. Shang) Subject: Black box or white box (Re: OO, C++, and something much better!) Date: 1997/01/30 Message-ID: <1997Jan30.144905.281@schbbs.mot.com>#1/1 X-Deja-AN: 213246652 sender: news@schbbs.mot.com (SCHBBS News Account) references: <32F07705.289C@concentric.net> organization: MOTOROLA reply-to: shang@corp.mot.com newsgroups: comp.lang.c++,comp.lang.smalltalk,comp.lang.eiffel,comp.lang.ada,comp.object Date: 1997-01-30T00:00:00+00:00 List-Id: In article <32F07705.289C@concentric.net> Alan Lovejoy writes: > Matt Kennel wrote: > > Alan Lovejoy (alovejoy@concentric.net) wrote: > > : An object should ideally be a black box that hides its implementation > > : (class). Exposing the interface of the object is acceptable, even good. > > : But most statically-typed OO languages go beyond that into exposing the > > : implementation (class)--and then hard coding it into type constraints on > > : variables in the program source, which is very, very bad. > > > > 1) Why is this very very bad? Why is it non-very bad? > > Because it fails to separate interface from implementation. > Be careful. Black boxes are not suitable for all the situiations. Sometimes white boxes are required, especiallly in the situiation where the clients want to have a touch and feel inside the box, not just to use the functionality of the box. Making all boxes black sometimes may complicate the usage of the box. For example, if I get a 3D model boxes with an built-in camera object, I would like to manipulate the camera by a direct touching and feeling the camera, rather than by some indirect handles (function interfaces) presented outside of the box. Have a look at the following code: class My_3DScene is World3D { with Camera { style = Perspective; position = (-1.0, 2.00, 8.0); orientation = (-0.2, -0.9, -1.5, 1.1); focalDistance = 12.5; }; with Background { style = Picturesque; scenery = "bluesky.jpg" }; object Light is DirectionalLight { direction = (0.0,-0.2,-1.0); }; object RollingFrame is Frame3D { object SphereFrame is Sphere { position = (0.0,0.0,0.0); radius = 8.0; draw_attr = DrawWire; }; object BlueCylinder is Cylinder { with Material { style = PerPart; diffuseColor = (0,0,1); specularColor = (0.5,0.5,1); shiness = 0.5; transparency = 0.6; } position = (1.0,0.0,0.0); radius = 1.0; hight = 3.0; }; } } It is certainly better than the the following: class My_3DScene is World3D { DirectionalLight Light; Frame3D RollingFrame; Sphere SphereFrame; Cylinder BlueCylinder; Material material; My_3DScene() // constructor { Camera.SetStyle(Perspective); Camera.SetPosition(-1.0, 2.00, 8.0); Camera.SetOrientation(-0.2, -0.9, -1.5, 1.1); Camera.SetFocalDistance(12.5); Background.SetStyle(Picturesque); Background.SetScenery("bluesky.jpg"); Light = new DirectionalLight (this); Light.SetDirection(0.0,-0.2,-1.0); RollingFrame = new Frame3D (this); SphereFrame = new Sphere (RollingFrame); SphereFrame.SetPosition(0.0,0.0,0.0); SphereFrame.SetRadius(8.0); SphereFrame.SetDrawAttr(DrawWire); BlueCylinder = new Cylinder (RollingFrame); material = BlueCylinder.GetMaterial(); material.SetStyle(PerPart); material.SetDiffuseColor(0,0,1); material.SetSpecularColor(0.5,0.5,1); material.SetShiness(0.5); material.SetTransparency(0.6); BlueCylinder.SetPosition(1.0,0.0,0.0); BlueCylinder.SetRadius(1.0); BlueCylinder.SetHight(3.00); }; }; The latter code hard to understand and manipulate. The class "World3D" is not designed to be used through its functionality, rather, it is designed for clients who can touch and feel the inside of the world! David Shang