Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security NachrichtenEU-Gesetz zur Cyber-Resilienz ist in Kraft - Netzpalaver(21.09.2026 um 20:29 Uhr)
Malware / Trojaner / VirenMeta Muse AI app flaw lets local malware redirect dictation traffic(21.09.2026 um 21:59 Uhr)
IT Security NachrichteniPhone 18 Pro (Max): Nutzer melden plötzliche Abstürze durch Face ID(21.09.2026 um 21:18 Uhr)
IT Security DownloadsEs wird Zeit, Word zu löschen(21.09.2026 um 21:53 Uhr)
IT NachrichtenAI can't outprompt a shortage of power, water, and land(21.09.2026 um 18:35 Uhr)
IT NachrichtenLondon neocloud Nscale takes its $1B loss to Wall Street(21.09.2026 um 19:15 Uhr)
IT Security NachrichtenEU-Gesetz zur Cyber-Resilienz ist in Kraft - Netzpalaver(21.09.2026 um 20:29 Uhr)
Malware / Trojaner / VirenMeta Muse AI app flaw lets local malware redirect dictation traffic(21.09.2026 um 21:59 Uhr)
IT Security NachrichteniPhone 18 Pro (Max): Nutzer melden plötzliche Abstürze durch Face ID(21.09.2026 um 21:18 Uhr)
IT Security DownloadsEs wird Zeit, Word zu löschen(21.09.2026 um 21:53 Uhr)
IT NachrichtenAI can't outprompt a shortage of power, water, and land(21.09.2026 um 18:35 Uhr)
IT NachrichtenLondon neocloud Nscale takes its $1B loss to Wall Street(21.09.2026 um 19:15 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Thinking in Objects

The procedural paradigm focuses on designing methods. The object-oriented paradigm couples data and methods together into objects. Software design using the object-oriented paradigm focuses on objects and operations on objects. Classes…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

The procedural paradigm focuses on designing methods. The object-oriented

paradigm couples data and methods together into objects. Software design using the object-oriented paradigm focuses on objects and operations on objects. Classes provide more flexibility and modularity for building reusable software. This section improves the solution for a problem introduced in previous post using the object-oriented approach. From these improvements, you will gain insight into the differences between procedural and object-oriented programming and see the benefits of developing reusable code using objects and classes.



ComputeAndInterpretBMI.java, here presented a program for computing body mass index. The code cannot be reused in other programs, because the code is in the main method. To make it reusable, define a static method to compute body mass index as follows:



public static double getBMI(double weight, double height)



This method is useful for computing body mass index for a specified weight and height. However, it has limitations. Suppose you need to associate the weight and height with a person’s name and birth date. You could declare separate variables to store these values, but these values would not be tightly coupled. The ideal way to couple them is to create an object that contains them all. Since these values are tied to individual objects, they should be stored in instance data fields. You can define a class named BMI as shown in Figure below.



Image description



Assume that the BMI class is available. The program below gives a test program that uses this class.



Image description



Line 6 creates the object bmi1 for Kim Yang and line 9 creates the object bmi2 for Susan King. You can use the instance methods getName(), getBMI(), and getStatus() to return the BMI information in a BMI object.



The BMI class can be implemented as in below.




package demo;

public class BMI {
private String name;
private int age;
private double weight; // in pounds
private double height; // in inches
public static final double KILOGRAMS_PER_POUND = 0.45359237;
public static final double METERS_PER_INCH = 0.0254;

public BMI(String name, int age, double weight, double height) {
this.name = name;
this.age = age;
this.weight = weight;
this.height = height;
}

public BMI(String name, double weight, double height) {
this(name, 20, weight, height);
}

public double getBMI() {
double bmi = weight * KILOGRAMS_PER_POUND / ((height * METERS_PER_INCH) * (height * METERS_PER_INCH));
return Math.round(bmi * 100) / 100;
}

public String getStatus() {
double bmi = getBMI();
if(bmi < 18.5)
return "Underweight";
else if(bmi < 25)
return "Normal";
else if(bmi < 30)
return "Overweight";
else
return "Obese";
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public double getWeight() {
return weight;
}

public double getHeight() {
return height;
}
}







The mathematical formula for computing the BMI using weight and height is given in linked post above. The instance method getBMI() returns the BMI. Since the weight and height are instance data fields in the object, the getBMI() method can use these properties to compute the BMI for the object.



The instance method getStatus() returns a string that interprets the BMI. The interpretation is also given in linked post.



This example demonstrates the advantages of the object-oriented paradigm over the procedural paradigm. The procedural paradigm focuses on designing methods. The object-oriented paradigm couples data and methods together into objects. Software design using the object-oriented paradigm focuses on objects and operations on objects. The object-oriented approach combines the power of the procedural paradigm with an added dimension that integrates data with operations into objects.



In procedural programming, data and operations on the data are separate, and this methodology requires passing data to methods. Object-oriented programming places data and the operations that pertain to them in an object. This approach solves many of the problems inherent in procedural programming. The object-oriented programming approach organizes programs in a way that mirrors the real world, in which all objects are associated with both attributes and activities. Using objects improves software reusability and makes programs easier to develop and easier to maintain. Programming in Java involves thinking in terms of objects; a Java program can be viewed as a collection of cooperating objects.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Thinking in Objects

Thematisch verwandte Begriffe: Thinking, Objects · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94494 | jshERP through 3.6 contains a tenant isolation bypass vulnerability that…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick