in Education by
This is kind of hard to explain, I hope my English is sufficient: I have a class "A" which should maintain a list of objects of class "B" (like a private List). A consumer of class "A" should be able to add items to the list. After the items are added to the list, the consumer should not be able to modify them again, left alone that he should not be able to temper with the list itself (add or remove items). But he should be able to enumerate the items in the list and get their values. Is there a pattern for it? How would you do that? If the question is not clear enough, please let me know. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
To prevent editing the list or its items you have to make them immutable, which means you have to return a new instance of an element on every request. See Eric Lippert's excellent series of "Immutability in C#": http://blogs.msdn.com/ericlippert/archive/tags/Immutability/C_2300_/default.aspx (you have to scroll down a bit)

Related questions

0 votes
    This is kind of hard to explain, I hope my English is sufficient: I have a class "A" which ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Which design pattern represents a way to access all the objects in a collection? (a) Iterator pattern (b) Facade ... & JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
0 votes
    In Network Management System, the division that is responsible for controlling access to network based on a ... Fault Management C. Security Management D. Active Management...
asked Feb 14, 2023 in Technology by JackTerrance
0 votes
    A rectifier type AC voltmeter consists of a series resistance R, an ideal full-wave rectifier bridge and a PMMC ... GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 16, 2021 in Education by JackTerrance
0 votes
    A 200 μA ammeter has an internal resistance of 200 Ω. The range is to be extended to 500μA. The shunt required ... for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 12, 2021 in Education by JackTerrance
0 votes
    Which design pattern provides a single class which provides simplified methods required by client and delegates call to ... of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What is Pattern matching enhancements in C#.Net?...
asked Dec 30, 2020 in Technology by JackTerrance
0 votes
    What is Garbage Collection in C#.Net?...
asked Jul 27, 2021 in Technology by JackTerrance
0 votes
    What is Data Access Object Pattern(DAO) pattern?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Nodes are managed by a controlling machine over ____________. 1. HTTP 2. HTTPs 3. FTP 4. SSH...
asked Jan 27, 2023 in Technology by JackTerrance
...