Share to: share facebook share twitter share wa share telegram print page

Class-based programming

Class-based programming, or more commonly class-orientation, is a style of object-oriented programming (OOP) in which inheritance occurs via defining classes of objects, instead of inheritance occurring via the objects alone (compare prototype-based programming).

The most popular and developed model of OOP is a class-based model, instead of an object-based model. In this model, objects are entities that combine state (i.e., data), behavior (i.e., procedures, or methods) and identity (unique existence among all other objects). The structure and behavior of an object are defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class. An object is similar to a structure, with the addition of method pointers, member access control, and an implicit data member which locates instances of the class (i.e., objects of the class) in the class hierarchy (essential for runtime inheritance features).

Encapsulation

Encapsulation prevents users from breaking the invariants of the class, which is useful because it allows the implementation of a class of objects to be changed for aspects not exposed in the interface without impact to user code. The definitions of encapsulation focus on the grouping and packaging of related information (cohesion) rather than security issues.

Inheritance

In class-based programming, inheritance is done by defining new classes as extensions of existing classes: the existing class is the parent class and the new class is the child class. If a child class has only one parent class, this is known as single inheritance, while if a child class can have more than one parent class, this is known as multiple inheritance. This organizes classes into a hierarchy, either a tree (if single inheritance) or lattice (if multiple inheritance).

The defining feature of inheritance is that both interface and implementation are inherited; if only interface is inherited, this is known as interface inheritance or subtyping. Inheritance can also be done without classes, as in prototype-based programming.

Critique

Class-based languages, or, to be more precise, typed languages, where subclassing is the only way of subtyping, have been criticized for mixing up implementations and interfaces—the essential principle in object-oriented programming. The critics say one might create a bag class that stores a collection of objects, then extend it to make a new class called a set class where the duplication of objects is eliminated.[1][2] Now, a function that takes an object of the bag class may expect that adding two objects increases the size of a bag by two, yet if one passes an object of a set class, then adding two objects may or may not increase the size of a bag by two. The problem arises precisely because subclassing implies subtyping even in the instances where the principle of subtyping, known as the Liskov substitution principle, does not hold. Barbara Liskov and Jeannette Wing formulated the principle succinctly in a 1994 paper as follows:

Subtype Requirement: Let be a property provable about objects of type . Then should be true for objects of type where is a subtype of .

Thus, normally one must distinguish subtyping and subclassing. Most current object-oriented languages distinguish subtyping and subclassing, however some approaches to design do not.

Also, another common example is that a person object created from a child class cannot become an object of parent class because a child class and a parent class inherit a person class but class-based languages mostly do not allow to change the kind of class of the object at runtime. For class-based languages, this restriction is essential in order to preserve unified view of the class to its users. The users should not need to care whether one of the implementations of a method happens to cause changes that break the invariants of the class. Such changes can be made by destroying the object and constructing another in its place. Polymorphism can be used to preserve the relevant interfaces even when such changes are done, because the objects are viewed as black box abstractions and accessed via object identity. However, usually the value of object references referring to the object is changed, which causes effects to client code.

Example languages

Although Simula introduced the class abstraction, the canonical example of a class-based language is Smalltalk. Others include PHP, C++, Java, C#, and Objective-C.

See also

References

  1. ^ Kiselyov, Oleg. "Subtyping, Subclassing, and Trouble with OOP". Retrieved 7 October 2012.
  2. ^ Ducasse, Stéphane. "A set cannot be a subtype of a bag". Retrieved 7 October 2012.

Read other articles:

Congressional CemeteryDetailsDidirikan4 April 1807Lokasi1801 E Street SE, Washington, D.C.NegaraAmerika SerikatJenisSwastaPemilikChrist ChurchLuas3.575 ekar (1.400 ha)Situs webSitus resmiFind a GraveCongressional CemeteryCongressional CemeteryDaftar Kawasan Bersejarah Nasional di ASU.S. National Historic LandmarkKoordinat:38°52′52″N 76°58′38″W / 38.88111°N 76.97722°W / 38.88111; -76.97722Koordinat: 38°52′52″N 76°58′38″W / 38.8811…

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Oktober 2016. TV laser adalah televisi proyeksi belakang yang menggantikan lampu bertegangan tinggi konvensional dengan lucutan tiga laser berwarna. Dengan sistem ini, TV laser dapat memberikan 90% warna yang bisa ditangkap oleh mata manusia sedangkan untuk plasma dan …

Pietro Lorenzetti, Basilika Assisi, 1310–1329 Pietro Lorenzetti (atau Pietro Laurati; c. 1280 – 1348) adalah seorang penulis Italia yang aktif antara c.1306 dengan 1345. Bersama dengan saudara bungsunya Ambrogio, ia mengenalkan naturalisme sampai seni Siena. Pranala luar Wikimedia Commons memiliki media mengenai Pietro Lorenzetti. Pietro Lorenzetti di Web Gallery of Art Pietro Lorenzetti di Panopticon Virtual Art Gallery Diarsipkan 2007-09-27 di Wayback Machine. Persondata Nama Lorenzetti, P…

Bagian dari seri tentang Gnostisisme Gnostisisme Persia Mandaeisme Manikheisme Gnostisisme Suriah-Mesir Setian Tomasin Valentinian Basilidean Para Bapak Gnostisisme Kristen Simon Magus Cerinthus Marsion Valentinius Gnostisisme Awal Ofit Keni Karpokratian Borborit Gnostisisme Pertengahan Bogomil Kathar Teks-teks Gnostik Perpustakaan Nag Hammadi Kisah perbuatan Tomas Allogenes 1 Wahyu Yakobus 2 Wahyu Yakobus Apokrifon Yohanes Kitab-kitab Jeu Percakapan Juruselamat Wahyu Koptik Paulus Injil Koptik …

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (مارس 2020) مجموعة الهياكل العظمية اليهوديةمعلومات عامةالاستعمال دعاية تحسين النسل النازي علم زائف الشخص المؤثر جوسيف كرامر[1]أغسطس هيرت[1]رودلف براندت البلد ألم…

Artikel ini bukan mengenai Kementerian Keamanan Publik (Tiongkok) atau Komisi Keamanan Nasional Partai Komunis Tiongkok. Lihat pula: Hukum Intelijensi Nasional Republik Rakyat Tiongkok Kementerian Keamanan Negara Republik Rakyat Tiongkok中华人民共和国国家安全部Zhōnghuá Rénmín Gònghéguó Guójiā Ānquán BùLambang Republik Rakyat TiongkokLambang Kementerian Keamanan NegaraBendera Kepolisian Rakyat TiongkokInformasi lembagaDibentuk1 Juli 1983; 40 tahun lalu (1983-07-01)Jen…

I Do, I DoPoster promosi untuk I Do, I DoGenreRomansa, Komedi, DramaDitulis olehJo Jung-hwaSutradaraKang Dae-sunPemeranKim Sun-aLee Jang-wooPark Geon-hyeongIm Soo-hyangNegara asalKorea SelatanBahasa asliKoreaJmlh. episode16ProduksiDurasiRabu dan Kamis 21:55 (KST)Rabu dan Kamis 20:00 (WIB)Rumah produksiKim Jong-hak ProductionDistributorMBC (2012)Rilis asliJaringanMBC (2012)Rilis30 Mei –19 Juli 2012 I Do, I Do (Hangul: 아이두 아이두) adalah seri romantis-komedi televisi Korea Selatan …

Commune in Ouest, HaitiDelmas DèlmaCommuneDelmasLocation in HaitiCoordinates: 18°33′0″N 72°18′0″W / 18.55000°N 72.30000°W / 18.55000; -72.30000Country HaitiDepartmentOuestArrondissementPort-au-PrinceArea • Total27.74 km2 (10.71 sq mi)Elevation194 m (636 ft)Population (2015)[1] • Total395,260 • Density14,249/km2 (36,900/sq mi) Delmas (Haitian Creole: Dèlma) is a commune in the Port…

Artikel ini bukan mengenai Liga Primer Indonesia. Lihat pula: Liga Super Indonesia 2011–12 Liga Prima IndonesiaNegara IndonesiaKonfederasiAFCMusim perdana2011–12Jumlah tim12Tingkat pada piramida1Degradasi keDivisi UtamaPiala domestikPiala IndonesiaPiala internasionalLiga Champions AFCPiala AFCJuara bertahan ligaSemen Padang FC (2011–12)Televisi penyiarRCTIMNCTVGlobal TVSINDOtvMNC Sports 2[1][2]Situs webhttp://www.premierleague.co.id Liga Prima Indonesia (bahasa Inggris…

Brazilian fantasy television series This article is about the Brazilian streaming television series. For other uses, see Invisible City (disambiguation). Invisible CityPortugueseCidade Invisível GenreFantasyCreated byCarlos SaldanhaBased onan original ideaby Raphael DracconCarolina MunhózWritten byMirna NogueiraDirected by Luis Carone Júlia Pacheco Jordão Starring Marco Pigossi Alessandra Negrini Fábio Lago Jessica Córes Jimmy London Wesley Guimarães Áurea Maranhão Julia Konrad Thaia Pe…

Bahrana National Space Agency National Space Science Agencyالهيئة الوطنية لعلوم الفضاءAgency overviewAbbreviationNSSAFormed2014TypeSpace agencyHeadquartersKingdom of BahrainAdministratorMohamed Al AseeriWebsitewww.nssa.gov.bh The National Space Science Agency (NSSA) (Arabic: الهيئة الوطنية لعلوم الفضاء) is the Bahraini government entity responsible for space science program. It was established by Royal Decree No. 11 for the Year 2014[1] and…

This article on a place of local interest may need more verifiable and notable information. Please review the essay guide and help improve the article. (April 2014) (Learn how and when to remove this template message) San José Jazz Summer FestGenreJazz, R&B, funk, popLocation(s)San Jose, CaliforniaCoordinates37°19′55″N 121°53′24″W / 37.332°N 121.89°W / 37.332; -121.89Years active1990–presentWebsitesummerfest.sanjosejazz.org Wide angle shot of the main s…

Artikel ini sebatang kara, artinya tidak ada artikel lain yang memiliki pranala balik ke halaman ini.Bantulah menambah pranala ke artikel ini dari artikel yang berhubungan atau coba peralatan pencari pranala.Tag ini diberikan pada Oktober 2022. Paraphrenia adalah gangguan mental yang mirip dengan skizofrenia dalam hal gejala positifnya (delusi dan atau halusinasi), tetapi tidak memiliki gejala negatif seperti gangguan kecerdasan atau kepribadian.[1][2][3] Dibandingkan den…

Junkers Ju 88Uno Junkers Ju 88 (matricola 3Z+H) assegnato al Kampfgeschwader 77 (I./KG 77) in voloDescrizioneTipobombardiereaereo da ricognizionecaccia notturnoaerosilurantezerstörer Equipaggio4[1] Costruttore Junkers Data primo volo21 dicembre 1936 Data entrata in servizio1939 Data ritiro dal servizio1951 Utilizzatore principale Luftwaffe Altri utilizzatoriSuomen ilmavoimat Ejército del Aire Esemplarioltre 16 000 Altre variantiJunkers Ju 188 Dimensioni e pesiTavole prospettiche L…

Stadio ex NATOVillaggio del Rugby Informazioni generaliStato Italia UbicazioneViale della Liberazione,Napoli Inaugurazione1954 Ristrutturazione2019 ProprietarioFondazione Banco di Napoli Informazioni tecnichePosti a sedere2 000 omologati StrutturaStadio CoperturaSolo tribuna centrale Pista d’atleticano Mat. del terrenoerba sintetica Uso e beneficiariRugbyAmatori Napoli Rugby, Rugby Napoli Afragola Mappa di localizzazione Modifica dati su Wikidata · ManualeCoordinate: 40°49′1…

Munisipalitas Luče Občina LučeMunisipalitasLokasi di SloveniaNegara SloveniaLuas • Total109,5 km2 (423 sq mi)Populasi (2013) • Total1.514 • Kepadatan1,4/km2 (3,6/sq mi)Kode ISO 3166-2SI-067Situs webhttp://www.luce.si/ Munisipalitas Luče adalah salah satu dari 212 munisipalitas di Slovenia. Kode ISO 3166-2 munisipalitas ini adalah SI-067. Menurut sensus 2013, jumlah penduduk munisipalitas yang luasnya 109,5 kilometer persegi in…

The PlaceCamden, London The PlaceThe PlaceLocation within LondonCoordinates51°31′38″N 0°7′43″W / 51.52722°N 0.12861°W / 51.52722; -0.12861TypeDrill HallSite historyBuilt1888–1889Built forWar OfficeArchitectRobert EdisIn use1889 – present The Place is a dance and performance centre in Duke's Road near Euston in the London Borough of Camden. It is the home of London Contemporary Dance School and the Robin Howard Dance Theatre, and formerly the Rich…

American physicist and science educator Melba Newell PhillipsBorn(1907-02-01)February 1, 1907Near Hazleton, Gibson County, IndianaDiedNovember 8, 2004(2004-11-08) (aged 97)Petersburg, IndianaAlma materOakland City University Battle Creek College University of California, BerkeleyAwardsOersted Medal (1974)Scientific careerInstitutionsBrooklyn College University of Minnesota Washington University University of ChicagoDoctoral advisorJ. Robert Oppenheimer Melba Newell Phillips (February 1…

Pour les articles homonymes, voir Physique et Quantique. Physique quantiqueHiérarchie des systèmes physiques dans l'infiniment petit et domaines scientifiques associés (les nombres indiquent les changements d'échelle entre chaque niveau).Pratiqué par Physicien quantique (d)Champs Mécanique quantiquemodifier - modifier le code - modifier Wikidata La physique quantique est un ensemble de théories physiques nées au XXe siècle, qui décrivent le comportement des atomes et des particule…

Medical issues associated with spaceflight This article is about the medical consequences of spaceflight on humans. For the general study, see Bioastronautics. American astronaut Marsha Ivins demonstrates the effects of microgravity on her hair in space The effects of spaceflight on the human body are complex and largely harmful over both short and long term.[1] Significant adverse effects of long-term weightlessness include muscle atrophy and deterioration of the skeleton (spaceflight o…

Kembali kehalaman sebelumnya