encapsulation

multiple parameters in class method

Total beginner question. I am attempting to create a method for a class that calculates the total price for an object based on int Quantity and decimal price. Both of these are private and have Instance Variable Property Assignments. I cannot figure out how to access them and compute on them when I am using two separate parameters in...

"Pinnacle" of Encapsulation - Question Regarding Advice from Effective C++

Item 23 of Effective C++ states: Prefer non-member non-friend functions to member functions. The whole purpose of the item was to encourage encapsulation, as well as package flexibility and functional extensibility, but my question is how far do you go when it comes to taking this advice? For example, you could have your class, your p...

Access to private Collection fields in Java

One of my classes has a field which contains a Set. This field is only ever filled in the constructor, and then read by other classes. Originally I had something like this: public class Foo { public final Set<String> myItems; public Foo(Collection<String> theirItems) { this.myItems = new LinkedHashSet<String>(theirItems)...

Clojure allows encapsulation and inheritance, but can I combine them?

Here is an overly simplistic example for illustration: I can encapsulate an implementation detail such as using an atom for a counter: (defn make-counter ([] (make-counter 0)) ([init-val] (let [c (atom init-val)] {:get (fn [] @c) :++ (fn [] (swap! c inc))}))) But that means I need to redefine everything to add a fea...

JavaScript function encapsulation outside the object

Please see the following script: var x = function(param){ this.data=param; this.y = function(){ alert(this.data) } return this; } /* x.prototype.z = function(){ alert(this.data); } */ x(123).y(); x(123).z(); // This should behave same as y() When I call x(123).y() then message displays 123. ...

In C#, can a method return List such that clients can only read it, but not write to it?

Let's say I have a C# class: class Foo { private List<Bar> _barList; List<Bar> GetBarList() { return _barList; } ... } A client can call it: var barList = foo.GetBarList(); barList.Add( ... ); Is there a way to make the Add method fail because only a read-only version of _barList is returned? ...

Doesn't Passing in Parameters that Should Be Known Implicitly Violate Encapsulation?

I often hear around here from test driven development people that having a function get large amounts of information implicitly is a bad thing. I can see were this would be bad from a testing perspective, but isn't it sometimes necessary from an encapsulation perspective? The following question comes to mind: http://stackoverflow.com/...

What technologies are good for sending encapsulated data, and later converting it, between Python and Objective-C?

Hello! I'm attempting to create a client/server web-app. The client software is written in Objective-C (Mac), and the server software is written in Python (Linux). I'd like to encapsulate object data on either side, and send it across the internet to the other side. This will include standard types such as strings, doubles, and data-...

Erasing a vector element by key

ive defined the following and filled it with elements: vector <vector<double> > my_vector; but i want a delete an element with a specific key... my_vector.erase(int(specific_key)); but it doesnt allow me. how would i properly dispose of the elements assigned to that key properly? ...

Isn't there a point where encapsulation gets ridiculous?

For my software development programming class we were supposed to make a "Feed Manager" type program for RSS feeds. Here is how I handled the implementation of FeedItems. Nice and simple: struct FeedItem { string title; string description; string url; } I got marked down for that, the "correct" example answer is as follo...

Abstraction of behavioural logic - is there a design pattern?

Hi all, I need to abstract some behavioural code and have a problem trying to reference the objects in the class that is calling these behaviours, let me try to explain: My "parent" class, has a property called CurrentPage. I also have some behavioural logic, that modifies the CurrentPage property, currently this is written in the same...

Recommendations on how to decouple services (RSS, REST API) from my UI (webforms) when they share a common model?

I have a web application that is arranged into data, business and UI projects. As the system evolves changes are deployed by building all three projects and deploying them in one package. This has worked well and has allowed the illusion of “three tiers” without tackling the communications, versioning issues of truly separate systems. ...

Should I encapsulate my IoC container?

I'm trying to decide whether or not it makes sense to go through the extra effort to encapsulate my IoC container. Experience tells me that I should put a layer of encapsulation between my apps and any third-party component. I just don't know if this is bordering on overkill. I can think of situations where I might want to switch cont...

How to encapsulate a std::set properly?

Hi, I have a class named Particle which has a std::set as a member. The class looks like this: class Particle { private: std::set<vtkIdType> cells; std::set<vtkIdType>::iterator ipc; public: Particle() {}; enum state {EXISTS = -1, SUCCESS = 0, ERROR = 1}; state addCell(const vtkIdType cell); int numCells() {...

Encapsulate other Apps in .Net MDI

Is it possible to encapsulate other windows apps in a .Net MDI form? The source code is not available for these apps... there's a set of programs we use that would be nice to have all wrapped into one app... An easy example would be maybe having a .net mdi form app that has a calculator button. When its clicked, it opens the windows cal...

Encapsulating Content In a Variable

Hello, I want to know how can I encapsulate the result(substr($text, 12)) of the variable $opt into itself(put the result replacing the expression substr($text, 12)), but how I can do this? If needed. Here is my code: my $text; my $opt = substr($text, 12); if ($command =~ /^Hello World Application/i) { print "$opt\n"; } # More code...

Why can't the VBA Me keyword access private procedures in its own module?

I just discovered that the Me keyword cannot access private procedures even when they are inside its own class model. Take the following code in Class1: Private Sub Message() Debug.Print "Some private procedure." End Sub Public Sub DoSomething() Me.Message End Sub This code instantiates an instance of the class: Sub TestCla...

How can I access data from a Ruby on Rails application externally?

I'm trying to work with the data in my Rails application from within a separate Ruby script. I read this forum post in which some people suggest that the best way to work with your data is to encapsulate the database within one application, and then have this application provide an API for working with that data. Because it's apparently...

I can't create a clear picture of implementing OOPS concepts, though I understand most of the OOPS concepts. Why ?

I have been working on some of the projects of my own and dont have any indrustial exposure. Currently i use simple approach for developing small applications with negligible OO approach like creating a common class for database functions using polymorphism of functions little bit use of constructors but i dont really able to think of ho...

Unit testing opaque structure based C API

I have a library I wrote with API based on opaque structures. Using opaque structures has a lot of benefits and I am very happy with it. Now that my API are stable in term of specifications, I'd like to write a complete battery of unit test to ensure a solid base before releasing it. My concern is simple, how do you unit test API based...